Show more action button for 3 points
We know from the above code that even if we do not show all action buttons on the horizontal screen. We can add a 3-point action button to display the action button with a drop-down display. Information on the Internet, as long as your phone has the menu key Actionbar will not show 3 points of more or 3 points of the menu button.
- Private void Getoverflowmenu () {
- try {
- viewconfiguration config = viewconfiguration.get (this);
- Field Menukeyfield = viewconfiguration. Class.getdeclaredfield ("Shaspermanentmenukey");
- if (Menukeyfield! = null) {
- Menukeyfield.setaccessible (true);
- Menukeyfield.setboolean (config, false);
- }
- } catch (Exception e) {
- E.printstacktrace ();
- }
- }
This method can be called in the Oncreat () method to display a menu button of 3 points. is the effect of pressing a 3-point action button
- For many pad: Actionbar space is sufficient to display, then the corresponding menu menu, only not set to Ifroom, and then can be placed in the overflow:
- For many phones: there are not enough controls in the Actionbar to display all the menus, even if the ifroom is set, many of the menus are still not fully displayed, so: even if you set the Ifroom menu item, and the menu item without the Ifroom set will be placed in the overflow
- <menu xmlns:android="http://schemas.android.com/apk/res/android" >
- <item
- android:id="@+id/menu_settings"
- android:orderincategory="
- android:showasaction="Never"
- android:title="Settings"/>
- <item
- android:id="@+id/action_refresh"
- android:icon="@drawable/navigation_refresh"
- android:orderincategory="101"
- android:showasaction="Ifroom|withtext"
- android:title="Refresh"/>
- <item
- android:id="@+id/action_about"
- android:icon="@drawable/action_about"
- android:orderincategory="101"
- android:showasaction="Ifroom"
- android:title="about"/>
- <item
- android:id="@+id/action_search"
- android:icon="@drawable/action_search"
- android:orderincategory="103"
- android:showasaction="ifroom"/>
- <item
- android:id="@+id/action_edit"
- android:icon="@android:d rawable/ic_menu_edit"
- android:orderincategory=" the"
- android:showasaction="Ifroom"
- android:title="edit"/>
- <item
- android:id="@+id/action_help"
- android:showasaction="Always"
- android:title="Help"/>
- <item
- android:id="@+id/action_email"
- android:icon="@android:d rawable/ic_dialog_email"
- android:orderincategory="106"
- android:showasaction="Ifroom"
- android:title="email"/>
- </Menu>
- Package com.example.demo_actionbarbasic;
- Import Com.example.demo_actionbarbasic. R
- Import Android.app.ActionBar;
- Import android.app.Activity;
- Import android.content.Intent;
- Import Android.os.Bundle;
- Import Android.view.Menu;
- Import Android.view.MenuItem;
- Import Android.widget.Toast;
- Public class Mainactivity extends Activity {
- private MenuItem MenuItem = null;
- @Override
- protected void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Setcontentview (R.layout.activity_main);
- //Through the Hilde () and Show () methods to control the hiding and display of Actionbar
- //ActionBar ActionBar = Getactionbar ();
- //Actionbar.hide ();
- //Actionbar.show ();
- }
- //We can see that the use of Actonbar is the same as the Options menu
- @Override
- Public Boolean oncreateoptionsmenu (Menu menu) {
- //inflate the menu; This adds items to the action bar if it is present.
- Getmenuinflater (). Inflate (R.menu.activity_main, menu);
- return true;
- }
- @Override
- Public Boolean onoptionsitemselected (MenuItem item) {
- switch (Item.getitemid ()) {
- Case R.id.action_refresh:
- Toast.maketext (This, "menu Item Refresh selected",
- Toast.length_short). Show ();
- Break ;
- Case R.id.action_about:
- Toast.maketext (This, "menu Item is about selected", Toast.length_short)
- . Show ();
- Break ;
- Case R.id.action_edit:
- Toast.maketext (This, "menu Item Edit selected", Toast.length_short)
- . Show ();
- Break ;
- Case R.id.action_search:
- Toast.maketext (This, "menu Item Search selected",
- Toast.length_short). Show ();
- Break ;
- Case R.id.action_help:
- Toast.maketext (This, "menu Item settings selected",
- Toast.length_short). Show ();
- Break ;
- Default:
- Break ;
- }
- return super.onoptionsitemselected (item);
- }
- }
Reprinted from: http://www.cnblogs.com/SharkBin/p/3559213.html
[Android] ActionBar Show Overflow (just three buttons behind)