如何自定义操作模式的颜色和文本?
默认操作模式(3.0 及更高版本)带有绿色主题和左侧的“完成”按钮。我如何定制这些?
谢谢
The default action mode (3.0 and up) comes with a green theme and a 'Done' button on the left side. How can I customize these?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这是用于任何 ActionMode 的样式,我从 SDK 中提取了它。您需要创建自己的样式来自定义它。这真的很容易做到。如果您以前从未做过类似的事情,您应该通读 这篇文章介绍了自定义 ActionBar。它解释了您需要了解的一切。
This is the style used for any ActionMode, I pulled it from the SDK. You'll need to create your own style to customize it. It's really easy to do. If you've never done anything like this before, you should read through this post on customizing the ActionBar. It explains everything you'll need to know.
我的应用程序的解决方案
Solution for my application
在我的项目中工作
自定义 ActionMode 样式
自定义标题 ActionMode
Worked on my project
Custom ActionMode style
Custom Title ActionMode
使用此代码,您可以更改操作模式的背景颜色,还可以更改完成图像。注意:您也可以在图像中添加文字!在 res/styles.xml 中:
with this code you can change the Background color of Action mode and also change DONE image. Note: you can add your text in your image too! in res/styles.xml:
您实际上无法通过这种方式自定义它,因为属性 actionModeStyle 是在 API 级别 14 中引入的。对于 API 级别 11 到 13,您就不走运了。
对于 API 级别 14,您可以通过在主题中设置 android:actionModeStyle 来更改样式。
You can't really customize it this way because the attribute actionModeStyle is introduced at API level 14. For API levels 11 to 13 you are out of luck.
For API level 14, you can change the style by setting the android:actionModeStyle in your theme.
这是我使用 Java 代码的方法:
Here is my approach with Java code:
更新了棒棒糖前和棒棒糖后设备的答案。您必须删除 android: 前缀才能使其在 Lollipop+ 设备上工作,如下所示:
styles.xml:
v21/styles.xml:
我还建议您使用
parent="@style/Widget.AppCompat 的样式.ActionMode"
设置,这样您就可以继承您不关心覆盖的属性。Updated answer for both pre- and post-Lollipop devices. You must remove the android: prefix to get it to work on Lollipop+ devices, like so:
styles.xml:
v21/styles.xml:
I'd also recommend having your style with
parent="@style/Widget.AppCompat.ActionMode"
set, so you inherit the attributes you don't care about overriding.这是一个 AppCompat(即使用 startSupportActionMode)解决方案,用于临时自定义(自定义)CAB 完成按钮的图像。暂时因为需要将其更改回使用其典型图像,以便当文本选择启动时它看起来合适。
https://gist.github.com/coreform/36ed98f98668f2e90c6a
Here's an AppCompat (i.e. using startSupportActionMode) solution for temporarily customizing (customising) the CAB done button's image. Temporarily since it's desirable to change it back to use it's typical image so that when Text Selection kicks in it looks appropriate.
https://gist.github.com/coreform/36ed98f98668f2e90c6a