<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
This worked for me
app:showAsAction="ifRoom|withText"
appcompat_v7 > values > config.xml
<bool name="abc_config_allowActionMenuItemTextWithIcon">false</bool>
change
<bool name="abc_config_allowActionMenuItemTextWithIcon">true</bool>
Related
The buttons on the action bar on this tablet, if shown with text, suffer from text warping as in the screenshot below:
I tried many possible settings combinations (ifRoom, always, withText,...). Even attempting to manipulate the actual view of the button get me nowhere (or maybe I didn't persevere enough). Setting the widths of the TextView and the parent LinearLayout had no effect unless they're fixed numbers.
Any ideas?
EDIT:
I neglected to mention that attempting to use an icon along with text only shows the icon. This is using the native action bar. Below is the xml of the action button above:
<item
android:id="#+id/itemConfig"
android:showAsAction="ifRoom|withText"
android:title="Network Config"
android:visible="true"/>
Setting the menu item in the following manner:
<item
android:id="#+id/itemConfig"
android:icon="#drawable/ic_action_networkconfig"
android:showAsAction="ifRoom|withText"
android:title="#string/network_config"
android:visible="true"/>
causes this
So in essence, the tablet doesn't like text in its action bar. Any clues?
It looks like your menu code is correct. For reference check my menu item xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/itemConfig"
android:icon="#drawable/icon"
app:showAsAction="withText|always"
android:title="#string/network_config"/>
</menu>
Device will show text with icon only if we have space. You can check with landscape mode. Here is the example
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.
Long story short, it couldn't be done :)
Before you Tag as a duplicate question: I've read:
Action buttons doesn't show up on Action Bar?
Action Bar not showing action view icons
and
Android: Icons don't appear in Action Bar
But the issue is not resolved. My action bar will only hold the menu items in the overflow. I cannot get the icons to appear on the action bar itself.
The code for my menu is:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/homeIcon"
android:title="#string/Home"
android:icon="#drawable/ic_home_black_24dp"
android:orderInCategory="1"
app:showAsAction="always" /></menu>
I have declared the support header files but it hasn't made a difference.
I tried replacing the word 'app' in "app:showAsAction" with my app name as it appears in #strings but it will not accept it because the app name has white space.
it is called my App instead of myApp.
Is there that the reason why i can't get any icons in my actionBar, if yes is there a way to resolve it.. without recreating my app? i tried changing the name in #strings and that didn't resolve the issue, so it could just as easily be something else.
Thanks in advance community!
Probably you are not using AppCompat (or not using it in this particular situation) then android:showAsAction. Yes, Android Studio will complain and recommend to use app:showAsAction but it works.
I am developing an application of my own and was reading this: http://developer.android.com/guide/topics/ui/menus.html
It says:
Beginning with Android 3.0, the Menu button is deprecated (some
devices don't have one), so you should migrate toward using the action
bar to provide access to actions and other options.
My app is only targeting android 4.2+. Does that mean I should present the menu options as only action bar icons ? What if there is not enough room available ?
Items that do not fit in the action bar will automatically be relegated to the overflow menu. All you have to do is set the android:showAsAction="ifRoom" property in your xml for the menu item.
This basically tells the system that this menu item should be displayed as an action icon if there is room available. If not, it should be shown as an overflow menu item.
It means that there is no more hardware Menu Button. Your menu items will be showed in popup under "three-doted icon". In menu.xml you can configure everything:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="#+id/action_example"
android:title="#string/action_example"
android:showAsAction="ifRoom" /> <!-- attention -->
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
Read more here
If you need a lot of icons to be showed you can split ActionBar(second(bottom) menu bar will appear).
documantation of splitting
I hope mine explanation will be good enough:)
As you guys can see, my app's name has been overlapped by Action bar's items. I have only two items in action bar.
Is it possible to show only one item there so that it couldn't overlap the app name and rest of the item/s in overflow menu(the default behavior..)?
Wondering why its not sensing the app name and arranging its items accordingly?
Edit (actionbar.xml):
<item
android:id="#+id/about"
android:title="#string/about"
android:showAsAction="ifRoom|withText"
>
</item>
<item
android:id="#+id/email"
android:title="#string/email"
android:showAsAction="ifRoom|withText">
</item>
Thanks.
Are you using ActionBarSherlock? I believe I had a similar problem until I changed my theme in my androidManifest.xml to be derived from Theme.Sherlock.ForceOverflow
Add to AndroidManifest.xml under application tag
android:theme="#style/Theme.Sherlock.ForceOverflow"
I have a slight problem trying to customise the look of the action bar in my app. I want to be able to have the pixel wide dividers to group action bar items that you see in many of the native apps (e.g. Gmail, Calendar). I found a way to do this by adding a menu item and setting the 'android:actionLayout' attribute to a custom layout for the divider:
<View
android:background="#color/LightGray"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_width="1dip"
android:layout_height="fill_parent" />
This works nicely, but the issue is it counts as a menu item and the action bar seems to limit the number of menu items to 4 - any others get pushed into the overflow menu.
So I guess what I'm asking is whether there is a standard way to add item dividers without having to use a menu item with a custom view, and in a way that doesn't count towards the limit for action bar items?
Thanks in advance!
I wouldn't try and force dividers into places that the system does not add them automatically as it will make your app inconsistent with the platform. The default behavior is:
Divider between overflow and others.
Divider between text and another item where it would disambiguate which item the text belongs to.
I couldn't find a standard way, but the way I did it was to use the android:actionLayout property for the menu item, and I put the divider in there.
When Google released the 3.0 SDK I got a quick demo app to see how the ActionBar works and just looking back at it, if I use Text Items without Icon drawables, then I get automatic dividers drawn.
My menu.xml file is like this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_text" android:showAsAction="ifRoom" android:title="#string/action_label_text" />
<item android:id="#+id/menu_text" android:showAsAction="ifRoom" android:title="#string/action_label_text" />
<item android:id="#+id/menu_text" android:showAsAction="ifRoom" android:title="#string/action_label_text" />
<item android:id="#+id/menu_text" android:showAsAction="ifRoom" android:title="#string/action_label_text" />
</menu>
Maybe this won't work with icons??
Or thinking about it, maybe the size of the icon has an effect?