简体   繁体   中英

ActionBar Not Clipping Menu Item Text

It would seem that there is an option to provide a title and a titleCondensed for an ActionBar item in the menu xml file. However, is there an additional way to signify that if there is not enough room to write a menu items text, that it would fade off much like you can do within other views. This only seems to occur with one language at that due to the longer wording.

At the moment it pushes an entire icon off-screen within portrait mode instead of clipping the text as I would have expected. Even though the text item is assigned the showAsAction="ifRoom" and the icons showAsAction="always".

Anyone run into the need for this? I could provide a condensed title, but would rather find the appeal in trailing text when room isn't available.

update

It even seems to choose the titleCondensed option no matter whether or not it has room to use the non-condensed version once it is introduced as well. So there must be some sort of hard-coded limit where it decides, rather than on space available as well or something?

In xml use this to show

android:showAsAction="always|withText"

and this to collapse

android:showAsAction="collapseActionView"

then this menu items with collapseActionView will show when you press menu hardware button in devices

If you want to show it in topactionbar use this, but not commended

private void getOverflowMenu() {

try {
    ViewConfiguration config = ViewConfiguration.get(this);
    Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
    if (menuKeyField != null) {
    menuKeyField.setAccessible(true);
    menuKeyField.setBoolean(config, false);
    }
} catch (Exception e) {
    e.printStackTrace();
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM