Android: compat:showAsAction="always|withText" 不工作
Android: compat:showAsAction="always|withText" not working
<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>
这是我的菜单 XML 文件,理论上它应该将两个图标显示为单个图标,第一个图标也带有标题。
然而,在应用程序中它不显示标题,这里是屏幕截图:
那为什么不显示"title"?
Android系统认为没有足够的空间来完整显示菜单项的标题,所以隐藏了标题(虽然可能有足够的空间,但Android没有'不这么认为。)如果您在平板电脑中变成横向或 运行 应用程序,标题将显示。
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
来源:
http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems
如果您的菜单项同时提供标题和图标(具有标题和图标属性),则默认情况下操作项仅显示图标。
如果要显示文本标题,请在 showAsAction 属性中添加 "withText"。
注意: "withText" 值是提示操作栏应该出现文本标题。 操作栏将尽可能显示标题,但如果图标可用且操作栏受限于 space。[=11=,则可能不会显示标题]
这对我有用
app:showAsAction="ifRoom|withText"
appcompat_v7 > 值 > config.xml
<bool name="abc_config_allowActionMenuItemTextWithIcon">false</bool>
改变
<bool name="abc_config_allowActionMenuItemTextWithIcon">true</bool>
<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>
这是我的菜单 XML 文件,理论上它应该将两个图标显示为单个图标,第一个图标也带有标题。
然而,在应用程序中它不显示标题,这里是屏幕截图:
那为什么不显示"title"?
Android系统认为没有足够的空间来完整显示菜单项的标题,所以隐藏了标题(虽然可能有足够的空间,但Android没有'不这么认为。)如果您在平板电脑中变成横向或 运行 应用程序,标题将显示。
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
来源: http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems
如果您的菜单项同时提供标题和图标(具有标题和图标属性),则默认情况下操作项仅显示图标。
如果要显示文本标题,请在 showAsAction 属性中添加 "withText"。
注意: "withText" 值是提示操作栏应该出现文本标题。 操作栏将尽可能显示标题,但如果图标可用且操作栏受限于 space。[=11=,则可能不会显示标题]
这对我有用
app:showAsAction="ifRoom|withText"
appcompat_v7 > 值 > config.xml
<bool name="abc_config_allowActionMenuItemTextWithIcon">false</bool>
改变
<bool name="abc_config_allowActionMenuItemTextWithIcon">true</bool>