0

I know two ways to show action bar icons. My minimum sdk is 14 and target sdk 19. I am debugging with android 4.2.

First one

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/mPre"
        android:icon="@drawable/ic_action_previous_item"
        android:showAsAction="always"
        android:title="Previous"/>
    <item
        android:id="@+id/mNext"
        android:icon="@drawable/ic_action_next_item"
        android:showAsAction="ifRoom"
        android:title="Next"/>
    <item
        android:id="@+id/mShare"
        android:icon="@drawable/ic_action_share"
        android:showAsAction="ifRoom"
        android:title="Share"/>
    <item
        android:id="@+id/mFb"
        android:icon="@drawable/fb"
        android:showAsAction="ifRoom"
        android:title="Facebook"/>
    <item
        android:id="@+id/mhelp"
        android:icon="@drawable/ic_action_help"
        android:showAsAction="ifRoom"
        android:title="Help"/>

</menu>

This will show icon dynamically (2 or 3 as consider space of action bar). But problem is, this is not showing extra menu in overflow icon. When I touch my phone menu bar, extra menu will appears, but I want extra menu in overflow icon.

For solution my second code.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/mPre"
        android:icon="@drawable/ic_action_previous_item"
        android:showAsAction="always"
        android:title="Previous"/>
    <item
        android:id="@+id/mNext"
        android:icon="@drawable/ic_action_next_item"
        android:showAsAction="always"
        android:title="Next"/>
    <item
        android:id="@+id/mMore"
        android:icon="@drawable/ic_action_overflow"
        android:showAsAction="always"
        android:title="More">
        <menu>
            <item
                android:id="@+id/mShare"
                android:icon="@drawable/ic_action_share"
                android:showAsAction="ifRoom"
                android:title="Share"/>
            <item
                android:id="@+id/mFb"
                android:icon="@drawable/fb"
                android:showAsAction="never"
                android:title="Facebook"/>
            <item
                android:id="@+id/mhelp"
                android:icon="@drawable/ic_action_help"
                android:showAsAction="never"
                android:title="Help"/>
        </menu>
    </item>

</menu>

The problem of this code this is not really dynamic. I am showing here two icon always and put others icon in overflow icon, this overflow icon is not real overflow icon.

Now what I want? I want if I have five menu as much as menu will show in action bar and rest of the icons are stored in overflow icon automatically.

I hope you guys get my problem. Please help me. Thanks in advance.

Xplosive
  • 711
  • 3
  • 14
  • 26
  • Are you saying you want the overflow menu icon to show up on the action bar on a phone which has a menu key? as far as I know that isn't possible. – casolorz Jun 05 '14 at 23:26

2 Answers2

0

i think you need to use this

 android:showAsAction="ifRoom|withText"

the parameter showAsAction decides where the icon is to be shown

refer to this link and the documentation

Community
  • 1
  • 1
thenoob
  • 63
  • 6
0

If I understand correctly, you want the the action bar icons to always show on the overflow? If that's the case, you can try the following:

<item
        android:id="@+id/action_settings"
        android:title="Test"
        app:showAsAction="never" />
fokusfocus
  • 195
  • 1
  • 3
  • 15