gpt4 book ai didi

android - 如何在运行时更改 TextColor auf ActionBarCompat MenuItem?

转载 作者:行者123 更新时间:2023-11-30 03:18:40 25 4
gpt4 key购买 nike

我需要在运行时更改 ActionBarCompat 中菜单项的文本颜色。有什么办法吗?

最佳答案

尝试使用 spannable 字符串来更改菜单项的文本。这是供您引用的示例代码。

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menuId, menu);
SpannableString str = new SpannableString("Menu item text");
str.setSpan(new ForegroundColorSpan(Color.BLUE), 0, str.length(), 0);
menu.getItem(R.id.menuItemId).setTitle(str);
}

关于android - 如何在运行时更改 TextColor auf ActionBarCompat MenuItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19566118/

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