分割 ActionBar 中的 withText
我遇到一个问题,如果 ActionItem
同时具有图标和文本,并且 ActionBar
被拆分,即使 showAsAction= ,它也只会显示图标“总是|withText”
。
有没有办法强制显示文字?
I'm having an issue where if the ActionItem
has both an icon and text and the ActionBar
is split, it will only show the icon even if the showAsAction="always|withText"
.
Is there a way to force the text to appear?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
withText
是对系统的提示。在宽度受限的设备或配置上,系统可能会选择忽略它。withText
is a hint to the system. On width-constrained devices or configurations the system may choose to ignore it.我最近遇到了同样的问题,正如 adamp 已经回答的那样,没有办法强制文本与“withText”选项一起出现。
实际上,这可以通过操作栏中的自定义视图来完成,例如在 Google 日历的编辑/创建事件屏幕中(操作栏中的“取消”和“保存”按钮,均带有文本)。
检查 Google 日历源代码,了解其操作方式
https://android.googlesource.com/platform /packages/apps/Calendar
中有一个 Actionbar 自定义视图的布局,
在res/layout/edit_event_custom_actionbar.xml
相关样式
另请检查EditEventFragment 类、方法中应用于 Actionbar 的 onCreateView
事件处理程序也在那里分配。
Actionbar 显示选项在 EditEventActivity 类的 onCreate 方法中设置:
这是我到目前为止所想到的。使用操作栏的标准菜单配置,对其他屏幕选项(平板电脑)进行了一些附加配置,但在我自己的代码中使用类似的布局、样式和这两个片段,产生了预期的结果(带有文本的操作栏项目)。
希望这有帮助
I had the same problem recently and as already answered by adamp, there is no way to force the text to appear with the "withText" option.
Actually this can be done with a custom view in the Actionbar as i.e. in The Google Calendar's Edit/Create Event Screen (Cancel and Save button in the action bar, both with text).
Check the Google Calendars source on how it is done
https://android.googlesource.com/platform/packages/apps/Calendar
there is a layout for the Actionbar custom View in
res/layout/edit_event_custom_actionbar.xml
please also check the related styles
this is applied to the Actionbar in the EditEventFragment class, method onCreateView
The event handlers are assigned there as well.
The Actionbar display option are set in the EditEventActivity class, onCreate method:
This is what I figured out so far. There is some additional configuration for other screen options (tablets) using the standard menu configuration for the actionbar, but using a similar layout, style and those two snippets in my own code, produced the expected result (actionbar item with text).
Hope this helps