2014-10-29 20 views
6

पर एक्शन मेनू को कैसे केंद्र करें मेरे पास split action bar एक एक्शन मेनू लोड करने वाला एक एप्लिकेशन है।टूलबार

मैं नए उपकरण पट्टी के लिए ActionBar बदल गया है और स्टैंडअलोन मोड में उपयोग एक अन्य उपकरण पट्टी से विभाजित ActionBar लाए गए:

Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbarBottom); 
toolbarBottom.inflateMenu(R.menu.ab_one_cam); 

प्रलेखन कार्रवाई मेनू उपकरण पट्टी के अधिकार के लिए पिन है में निर्दिष्ट के रूप में: enter image description here

लेकिन मैं प्रतीक चाहते हैं, उपकरण पट्टी पर केंद्रित किया जाना है जैसे कि यह विभाजन ActionBar पर था: enter image description here

मैं क्रिया मेनू को टूलबार पर सभी उपलब्ध स्थान कैसे ले सकता हूं?

टूलबार इस मेनू को समर्पित है, इसमें कुछ भी नहीं जोड़ा जाएगा।

उत्तर

स्वीकार किए जाते हैं जवाब के लिंक एक विभाजन उपकरण पट्टी करने के लिए नेतृत्व। मेरे जैसे आप बहुत ही सरल की जरूरत है, तो इस कोड को काफी अच्छा है: https://gist.github.com/dodgex/7bc81fd2cbb70a8d5117

+0

चेक भी: http://stackoverflow.com/questions/34546160/how-to-enable-split-action-bar/34546493#34546493 – piotrek1543

उत्तर

6

इस मामले में, क्रिस बेंस टूलबार के बजाय ActionMenuView उपयोग करें (नीचे लिंक देखें, उत्तर # 6) को सलाह देते हैं। इसके अलावा, इस लिंक में आप एक समाधान ढूंढ सकते हैं जहां लड़का स्प्लिट कार्यों के लिए टूलबार को उप-वर्गीकृत करता है।

https://code.google.com/p/android/issues/detail?id=77632#c2

आशा है कि यह आप में मदद करता है!

+1

थ्रेड की टिप्पणी में विस्तृत स्प्लिट टूलबार का उपयोग करके चाल है: https://gist.github.com/dodgex/7bc81fd2cbb70a8d5117 – grunk

1

मैं यह भी इस सवाल का पिछले कुछ हफ्तों के लिए एक जवाब खोजने की कोशिश कर रहा है:

public class SplitToolbar extends Toolbar { 

    public SplitToolbar(Context context) { 
     super(context); 
    } 

    public SplitToolbar(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public SplitToolbar(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @Override 
    public void addView(View child, ViewGroup.LayoutParams params) { 
     if (child instanceof ActionMenuView) { 
      params.width = LayoutParams.MATCH_PARENT; 
     } 
     super.addView(child, params); 
    } 
} 

क्रेडिट करने के लिए चला जाता है। और मुझे मिली सबसे नज़दीकी चीज इस तथ्य का लाभ उठाती है कि Toolbar सिर्फ एक व्यू ग्रुप है। आपको केवल menu_items लेआउट बनाना है जो समान रूप से भारित menu items के साथ LinearLayout है। मुझे पता है कि यह एक आदर्श समाधान नहीं है लेकिन डिफ़ॉल्ट मेनू का उपयोग करते समय आइटम को फैलाने के लिए मुझे वैसे भी नहीं मिला है।

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar_btm" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:minHeight="?attr/actionBarSize" 
     android:background="@color/toolbar_bkgnd" 
     android:layout_alignParentBottom="true" 
     app:theme="@style/ThemeOverlay.AppCompat.ActionBar" > 

     <include layout="@layout/menu_items"/> 

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

आप अभी भी इस समाधान के साथ inflateMenu() और setOnMenuItemClickListener() का उपयोग कर सकते हैं? – grunk

+0

हां और नहीं। यदि आप ओवरफ्लो मेनू का उपयोग कर रहे हैं तो भी आप उन लोगों के लिए डिफ़ॉल्ट विधियों का उपयोग कर सकते हैं, हालांकि अन्य मेनू आइटम्स के लिए आपको एक्सएमएल के माध्यम से लेआउट सेट करना होगा और ऑनक्लिक घटनाओं को स्वयं सुनना होगा। – MrEngineer13

+0

तब टूलबार का उपयोग करने का कोई कारण नहीं, बेहतर कस्टम व्यू बनाएं :( – grunk

संबंधित मुद्दे