简体   繁体   中英

Showing Icons for hidden Actionbar items

I have an actionabar and I have hidden some of its items by:

android:showAsAction="never" 

So these Items appear in the three dots area (the popup menu) . But then the icons won't be shown.
I thought these is the common behavior in android and you cannot show any icons in the three dots area. But then I saw a sample where android itself uses items in this area, but all have icons.
For example some apps have a Share item in the three dots area and if you click on it, some apps (like facebook, twitter etc.) appear in the popu menu and all of them have icons.
How can I show items in the three dots area (in the popup menu) that have icons or images?

You can use actionbarsherlock to achieve the same.

make sure you extends SherlockActivity .

@Override
    public boolean onCreateOptionsMenu(Menu menu) {

         MenuInflater inflater = getSupportMenuInflater();  
            inflater.inflate(R.menu.main, menu);

            SubMenu subMenu = menu.addSubMenu(0, 0, 2, "ITEM");

            subMenu.add(0, 2, 2, "ITEM1")
            .setIcon(R.drawable.ur_icon);

            subMenu.add(0, 3, 3, "ITEM2")
            .setIcon(R.drawable.ur_icon);

            MenuItem subMenuItem = subMenu.getItem();
            subMenuItem.setIcon(R.drawable.abs__ic_menu_moreoverflow_holo_dark);
            subMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

            return super.onCreateOptionsMenu(menu);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM