Programmatically Display Actionbar Overflow June 11, 2023 Post a Comment I have an actionbar with a menu. When you click the button, the menu shows up and all is well with the world. this answer here's how you can do it:View mOverflow; @OverrideprotectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final View decor = getWindow().getDecorView(); decor.post(newRunnable() { @Overridepublicvoidrun() { ArrayList<View> results = newArrayList<>(); decor.findViewsWithText(results, "OVERFLOW", View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (results.size() == 1) { mOverflow = results.get(0); } } }); } @OverridepublicbooleanonCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); returntrue; } privatevoidshowMenu() { actionbar.show(); mOverflow.performClick(); } CopyAnd in your styles.xml:<stylename="AppTheme"parent="android:Theme.Holo"><itemname="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item></style><stylename="Widget.ActionButton.Overflow"parent="@android:style/Widget.Holo.ActionButton.Overflow"><itemname="android:contentDescription">OVERFLOW</item></style>CopyfindViewsWithText requires API 14+, however the answer I linked, has a solution for lower APIs. Share You may like these postsActionbarsherlock Restart To Apply Theme Triggers Wrong Lifecycle MethodsIs There A Standard Way To Add Dividers Between Action Bar Items In Android 3.0?How Can I Add My Spinner To The Actionbar?Add An Actionbar For Each Fragment Post a Comment for "Programmatically Display Actionbar Overflow"
Post a Comment for "Programmatically Display Actionbar Overflow"