2015-05-29 2 views
6

में कस्टम टूलबार बनाना मैं टूलबार में एक संपादन टेक्स्ट के साथ एंड्रॉइड में एक कस्टम विस्तारित टूलबार बनाने की कोशिश कर रहा हूं। लेआउट है कि मैं लागू करना चाहते हैं इसएंड्रॉइड

enter image description here

तरह दिखता कोड है कि मैं लागू करने के लिए लिखा है कुछ इस तरह है:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/my_awesome_toolbar" 
    android:layout_height="256dp" 
    android:layout_width="match_parent" 
    android:minHeight="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 

    > 

    <EditText 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/searchbox" 
     android:layout_alignParentBottom="true" 
     android:text="Test" 
     android:background="#ffffff" 
     /> 

</android.support.v7.widget.Toolbar> 

और गतिविधि निम्नलिखित है कोड

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar); 
    if (toolbar != null) { 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayShowTitleEnabled(false); 
     getSupportActionBar().setDisplayShowHomeEnabled(false); 
    }} 

लेकिन डब्ल्यू टोपी मुझे इसके बजाय मिलती है: enter image description here

विस्तारित टूलबार को अनुकूलित करने के बारे में बहुत सारे ट्यूटोरियल नहीं हैं, इसलिए वास्तव में कुछ मदद की सराहना करेंगे।

+0

हो सकता है कि यह आपकी मदद कर सकते हैं: http://stackoverflow.com/questions/31231609/creating -ए-बटन-इन-एंड्रॉइड-टूलबार/31477092 # 31477092 – Machado

उत्तर

2

मैं तुम्हें वैसे ही जैसे टूलबार सेटिंग पर गुरुत्वाकर्षण = "नीचे" जोड़ने की जरूरत है लगता है: मैं लेआउट की तह तक कुछ मार्जिन जोड़ने के लिए प्रकट करने के लिए संपादित पाने के लिए था

<android.support.v7.widget.Toolbar 
    android:id="@+id/my_awesome_toolbar" 
    android:gravity="bottom" 
    android:layout_height="256dp" 
    android:layout_width="match_parent" 
    android:minHeight="?attr/actionBarSize" 
    android:background="?attr/colorPrimary"> 

लेकिन यह है कि ऐसा करना चाहिए पाठ के संपादन के नीचे पाठ प्राप्त करें।

या आप EditText पर layout_gravity सेट कर सकते हैं।

 <EditText 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:layout_gravity="bottom" 
     android:id="@+id/searchbox" 
     android:text="Test" 
     android:background="#ffffff"/> 

मैं आश्चर्यचकित हूं अभिभावकबॉटम संकलन। मुझे विश्वास नहीं है कि टूलबार रिलेवेटिवआउट से प्राप्त होता है।

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context=".MainActivity"> 

<android.support.v7.widget.Toolbar 
    android:id="@+id/my_awesome_toolbar" 
    android:layout_height="264dp" 
    android:layout_width="match_parent" 
    android:layout_alignParentBottom="true" 
    android:minHeight="?attr/actionBarSize" 
    android:background="?attr/colorPrimary"> 

    <EditText 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:layout_gravity="bottom" 
     android:id="@+id/searchbox" 
     android:text="Test" 
     android:background="#ffffff"/> 
</android.support.v7.widget.Toolbar> 
</RelativeLayout> 

कौन इस में जो परिणाम:: -

संपादित करें यहाँ मेरा पूरा लेआउट है

ToolBar

+0

मैंने इसके साथ भी कोशिश की है। यह इसे एक अजीब तरीके से प्रदर्शित करता है। आप इस स्क्रीनशॉट में परिणाम देख सकते हैं- https://dl.pushbulletusercontent.com/LKPBxwLnZez8neMwpuaNZXMmjTWbiDyO/Screenshot_2015-05-29-22-29-05.png इसके अलावा, समस्या यह भी है कि चौड़ाई ठीक से गठबंधन नहीं है संपादन पाठ के दोनों तरफ। –

+0

यह समस्या अधिक लोगों द्वारा देखी गई - http://stackoverflow.com/questions/27007985/support-toolbars-custom-view-not-using-full-width http://stackoverflow.com/questions/29239254/extended -toolbar-with-custom-view-not-displaying-with-full-width हालांकि इसका स्पष्ट समाधान न देखें। –

+0

http://stackoverflow.com/a/29648396/1268021 इसे हल करने के लिए लगता है। –