Android ActionBar compat overflow menu not showing on sdk 10

后端 未结 3 1313
被撕碎了的回忆
被撕碎了的回忆 2021-01-05 11:05

Hello and thank you for the time you take in reading this question.

I am trying to develop an android app which will use the ActionBar compat library. I have followe

相关标签:
3条回答
  • 2021-01-05 11:45

    I found the answer finally for this situation.

    All you need to do is call the following in the OnCreate in your activity

    ActionBarPolicy.get(this).showsOverflowMenuButton();
    
    0 讨论(0)
  • 2021-01-05 11:46

    @Andrei Google have disabled the menu overflow button in appcompat on pre honycomb. If You really want to add it go to the android's github repository and download platform_frameworks_support. It contains sorce for appcompat in platform_framework_support_master/v7/appcompat.

    Create a libs folder inside appcompat and put latest android-support-v4.jar. Now open file v7/appcompat/src/android/support/v7/internal/view/ActionBarPolicy.java. You will see that showOverflowMenuButton is returned false for pre honycomb.Just return it true and add this edited appcompat as library to your project and you will not need any custom overflow button This worked with me. Sorry for my English

    EDIT: actual code from android/support/v7/internal/view/ActionBarPolicy.java

    public boolean showsOverflowMenuButton() {
        // Only show overflow on HC+ devices
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
    }
    
    0 讨论(0)
  • 2021-01-05 12:02

    Try to show as I did.

    I add overflow menu (three dots) manually:

    <item
        android:id="@+id/menu_more"
        android:icon="@drawable/abc_ic_menu_moreoverflow_normal_holo_light"
        android:title="@string/action_settings"
        myapp:showAsAction="always">
        <menu>
            <item
                android:id="@+id/submenu_about"
                android:showAsAction="always"
                android:title="@string/menu_about"/>
        </menu>
    </item>
    

    and override menu button click in activity to show this menu (solution from Opening submenu in action bar on Hardware menu button click):

    private Menu mainMenu;    
    
    ...
    
    @Override
        public boolean onKeyUp(int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_MENU:
    
                    mainMenu.performIdentifierAction(R.id.menu_more, 0);
                    return true;
                }
    
            }
            return super.onKeyUp(keyCode, event);
        }
    

    Result on 2.2 looks like:

    Android 2.2 Overflow menu

    Hope it helps you.

    0 讨论(0)
提交回复
热议问题