[Android] ActionBar Show Overflow (just three buttons behind)

Source: Internet
Author: User

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.

  1. Private void Getoverflowmenu () {
  2. try {
  3. viewconfiguration config = viewconfiguration.get (this);
  4. Field Menukeyfield = viewconfiguration.  Class.getdeclaredfield ("Shaspermanentmenukey");
  5. if (Menukeyfield! = null) {
  6. Menukeyfield.setaccessible (true);
  7. Menukeyfield.setboolean (config, false);
  8. }
  9. } catch (Exception e) {
  10. E.printstacktrace ();
  11. }
  12. }


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
  1. <menu xmlns:android="http://schemas.android.com/apk/res/android" >
  2. <item
  3. android:id="@+id/menu_settings"
  4. android:orderincategory="
  5. android:showasaction="Never"
  6. android:title="Settings"/>
  7. <item
  8. android:id="@+id/action_refresh"
  9. android:icon="@drawable/navigation_refresh"
  10. android:orderincategory="101"
  11. android:showasaction="Ifroom|withtext"
  12. android:title="Refresh"/>
  13. <item
  14. android:id="@+id/action_about"
  15. android:icon="@drawable/action_about"
  16. android:orderincategory="101"
  17. android:showasaction="Ifroom"
  18. android:title="about"/>
  19. <item
  20. android:id="@+id/action_search"
  21. android:icon="@drawable/action_search"
  22. android:orderincategory="103"
  23. android:showasaction="ifroom"/>
  24. <item
  25. android:id="@+id/action_edit"
  26. android:icon="@android:d rawable/ic_menu_edit"
  27. android:orderincategory=" the"
  28. android:showasaction="Ifroom"
  29. android:title="edit"/>
  30. <item
  31. android:id="@+id/action_help"
  32. android:showasaction="Always"
  33. android:title="Help"/>
  34. <item
  35. android:id="@+id/action_email"
  36. android:icon="@android:d rawable/ic_dialog_email"
  37. android:orderincategory="106"
  38. android:showasaction="Ifroom"
  39. android:title="email"/>
  40. </Menu>
  1. Package com.example.demo_actionbarbasic;
  2. Import Com.example.demo_actionbarbasic. R
  3. Import Android.app.ActionBar;
  4. Import android.app.Activity;
  5. Import android.content.Intent;
  6. Import Android.os.Bundle;
  7. Import Android.view.Menu;
  8. Import Android.view.MenuItem;
  9. Import Android.widget.Toast;
  10. Public class Mainactivity extends Activity {
  11. private MenuItem MenuItem = null;
  12. @Override
  13. protected void OnCreate (Bundle savedinstancestate) {
  14. super.oncreate (savedinstancestate);
  15. Setcontentview (R.layout.activity_main);
  16. //Through the Hilde () and Show () methods to control the hiding and display of Actionbar
  17. //ActionBar ActionBar = Getactionbar ();
  18. //Actionbar.hide ();
  19. //Actionbar.show ();
  20. }
  21. //We can see that the use of Actonbar is the same as the Options menu
  22. @Override
  23. Public Boolean oncreateoptionsmenu (Menu menu) {
  24. //inflate the menu; This adds items to the action bar if it is present.
  25. Getmenuinflater (). Inflate (R.menu.activity_main, menu);
  26. return true;
  27. }
  28. @Override
  29. Public Boolean onoptionsitemselected (MenuItem item) {
  30. switch (Item.getitemid ()) {
  31. Case R.id.action_refresh:
  32. Toast.maketext (This, "menu Item Refresh selected",
  33. Toast.length_short). Show ();
  34. Break ;
  35. Case R.id.action_about:
  36. Toast.maketext (This, "menu Item is about selected", Toast.length_short)
  37. . Show ();
  38. Break ;
  39. Case R.id.action_edit:
  40. Toast.maketext (This, "menu Item Edit selected", Toast.length_short)
  41. . Show ();
  42. Break ;
  43. Case R.id.action_search:
  44. Toast.maketext (This, "menu Item Search selected",
  45. Toast.length_short). Show ();
  46. Break ;
  47. Case R.id.action_help:
  48. Toast.maketext (This, "menu Item settings selected",
  49. Toast.length_short). Show ();
  50. Break ;
  51. Default:
  52. Break ;
  53. }
  54. return super.onoptionsitemselected (item);
  55. }
  56. }

Reprinted from: http://www.cnblogs.com/SharkBin/p/3559213.html

[Android] ActionBar Show Overflow (just three buttons behind)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.