<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_chat"
android:icon="@drawable/ico_enter_chat"
android:title="Enter Chat"
compat:showAsAction="always|withText" />
<item android:id="@+id/action_map"
android:icon="@drawable/ico_map"
android:title="Users Map"
compat:showAsAction="always" />
<item android:id="@+id/action_logout"
android:icon="@drawable/ico_log_out"
android:title="Log Out"
compat:showAsAction="always" />
</menu>
Here is my menu XML file, in theory it should display two icons as single icons and first icon with title too.
However, in app it doesn't display title, here is screencap:
So why doesn't it display "title" ?
Source: http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems
If your menu item supplies both a title and an icon—with the title and icon attributes—then the action item shows only the icon by default.
If you want to display the text title, add "withText" to the showAsAction attribute.
Note: The "withText" value is a hint to the action bar that the text title should appear. The action bar will show the title when possible, but might not if an icon is available and the action bar is constrained for space.
The Android system thought that there is no enough room to display the title of the menu item completely, so it hides the title (although there might be enough room, but Android doesn't think so.) If you turn into landscape or run the app in a tablet, the title will show up.
This declares that the Search action should appear as an action button when room is available in the action bar, but the Settings action should always appear in the overflow. (By default, all actions appear in the overflow, but it's good practice to explicitly declare your design intentions for each action.)
https://developer.android.com/training/basics/actionbar/adding-buttons.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With