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.
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
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" />
Related
How to add a text view in my Action bar to show data in android application.
Following is my menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<menu>
<item
android:id="#+id/action_log"
android:title="#string/action_log"
android:showAsAction="never"/>
<item
android:id="#+id/account_log"
android:title="#string/accountlog"
android:showAsAction="never"/>
<item android:id="#+id/logout"
android:title="Logout"
android:showAsAction="never"/>
</menu>
</menu>
Any changes required in strings.xml?
Change
android:showAsAction="never"
to
android:showAsAction="ifRoom"
Please check the correct case of ifRoom, I am not quite sure.
Solved by Using custom action bar Thank you all
I am placing icons to action bar. It looks like this:
Why search icon is more white? I want to do same color with setting icon. How can I do this?
My xml:
<item android:id="#+id/action_favorites"
android:icon="#drawable/ic_search"
android:title="Takip Listesi"
android:showAsAction="always" />
<item android:id="#+id/action_settings"
android:icon="#drawable/ic_action_settings"
android:title="Settings"
android:showAsAction="always" />
My images:
http://www.imgim.com/ic_action_search.png
http://imgim.com/image/ic_action_settings.png
Note: Images are white, probably you can't see on browser. Please download it.
I want to display overflow menu in android actionbar.
In all device i need same design app name at left side of actionbar and overflow icon at right side with menu in it.
Currently when i run app menu are showing on clicking of menu icon.
I just want to show menu like attached image-
below is my code inside menu.xml -
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_red"
android:orderInCategory="1"
android:showAsAction="never"
android:title="#string/news"/>
<item
android:id="#+id/menu_green"
android:orderInCategory="2"
android:showAsAction="never"
android:title="#string/online_test"/>
how to show menu in such way.
Thanks in advance.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
android:id="#+id/action_settings"
android:orderInCategory="100"
android:showAsAction="always"
<menu>
<item
android:id="#+id/menu_red"
android:title="red"/>
<item
android:id="#+id/menu_green"
android:title="green"/>
</menu>
</item>
this worked for me maybe work for you too
I have used actionbar in my app. I have 3 icons on actionbar, but when the app runs it only shows 2 icons i.e. First and the last one, not mid one. I want to show all of them everytime.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<!-- Share, should appear as action button -->
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_action_share"
android:showAsAction="ifRoom"
android:title="Generate QR"
yourapp:showAsAction="ifRoom"/>
**<!-- NOT SHOWING THIS ONE -->
<item
android:id="#+id/action_save"
android:icon="#drawable/ic_action_save"
android:showAsAction="ifRoom"
android:title="Generate QR"
yourapp:showAsAction="ifRoom"/>**
<item
android:id="#+id/action_nav_menu"
android:icon="#drawable/ic_action_overflow"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="Menu"
yourapp:showAsAction="always"/>
As you want all 3 items to be displayed every time, include yourapp:showAsAction="always" in each item.
I have set three action items which am adding to the ABS through menu XML like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_share_app"
android:icon="#drawable/share_ab"
android:showAsAction="collapseActionView"
android:title="#string/menu_share_app"/>
<item
android:id="#+id/menu_search"
android:icon="#drawable/share_ab"
android:showAsAction="always"
android:title="#string/menu_search"/>
<item
android:id="#+id/menu_settings"
android:icon="#drawable/share_ab"
android:showAsAction="collapseActionView"
android:title="#string/menu_settings"/>
</menu>
I want to show the search item alwys and the other two in a dropdown, I made the showasaction as "collapseActionView" but am not getting any dropdown. Here's the sample pic of what am expecting. Thanks! :)
I just changed the code and order.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_search"
android:icon="#drawable/share_ab"
android:showAsAction="always"
android:title="#string/menu_search"/>
<item
android:id="#+id/menu_share_app"
android:icon="#drawable/share_ab"
android:showAsAction="never"
android:title="#string/menu_share_app"/>
<item
android:id="#+id/menu_settings"
android:icon="#drawable/share_ab"
android:showAsAction="never"
android:title="#string/menu_settings"/>
</menu>
If you are having physical menu button (e.g. Nexus S) in your device then the dot line will not show. Even if your AVD emulates a device with has physical menu button then same thing will happen. When you press the Menu button it’ll show up.