Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android withText option does not work for action bar buttons on Huawei MediaPad (T1-A21L)

The buttons on the action bar on this tablet, if shown with text, suffer from text warping as in the screenshot below:

enter image description here

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

enter image description here

So in essence, the tablet doesn't like text in its action bar. Any clues?

like image 579
mido Avatar asked May 09 '16 15:05

mido


2 Answers

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 portarit mode landscape mode

like image 105
Akash Jain Avatar answered Nov 20 '22 16:11

Akash Jain


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.

like image 30
Yogesh Rathi Avatar answered Nov 20 '22 16:11

Yogesh Rathi