gpt4 book ai didi

Android动态更改菜单项文本颜色

转载 作者:行者123 更新时间:2023-11-29 00:03:36 31 4
gpt4 key购买 nike

我正在尝试动态更改菜单项文本颜色。

我有一个适用于菜单图标的解决方案,它使用如下滤色器:

Drawable drawable = menuItem.getIcon();

if (drawable != null) {
drawable.mutate();
drawable.setColorFilter(new
PorterDuffColorFilter(Color.parseColor(color), PorterDuff.Mode.MULTIPLY));
}
menuItem.setIcon(drawable);

输出:enter image description here

我无法更改菜单项文本的颜色。为了完成这项工作,我使用了以下代码:

 SpannableString s = new SpannableString(menuItem.getTitle());
s.setSpan(new ForegroundColorSpan(Color.parseColor(color)), 0, s.length(), 0);
menuItem.setTitle(s);

输出:enter image description here

“SAVE”的颜色是我想要改变的。

谁能帮我解决这个问题?

最佳答案

试试这个,

以样式添加此主题。

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">    
<item name="actionMenuTextColor">@color/text_color</item>
</style>

并将主题应用到工具栏

 android:theme="@style/AppTheme"

关于Android动态更改菜单项文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44173853/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com