简体   繁体   English

ActionBar不剪切菜单项文本

[英]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. 似乎可以在菜单xml文件中为ActionBar项目提供标题和titleCondensed选项。 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". 即使为文本项分配了showAsAction =“ ifRoom”和图标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. 甚至在引入非压缩版本后,它是否似乎也有选择使用titleCondensed选项的可能性。 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 在xml中使用它来显示

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 然后当您在设备中按菜单硬件按钮时,将显示带有collapseActionView的菜单项

If you want to show it in topactionbar use this, but not commended 如果要在topactionbar中显示它,请使用它,但不值得推荐

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();
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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