Programmatically Display Actionbar Overflow May 11, 2024 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 postsAdd Action Bar With Back Button In Preference ActivityAndroid Toolbar Overflow Menu Change Text Color And Fill Menu To The ScreenActionbar Aka Toolbar Is Black After Upgrade To Support Library V21I Want To Remove The Divider Under The Action Bar Post a Comment for "Programmatically Display Actionbar Overflow"
Post a Comment for "Programmatically Display Actionbar Overflow"