通过设置以下内容,可以轻松地在操作栏中设置项目背景的默认颜色:
<item name="android:actionBarItemBackground">@drawable/action_bar_item_background</item>
在应用程序主题中,我想仅针对一个片段更改此颜色。如何以编程方式实现?
通过设置以下内容,可以轻松地在操作栏中设置项目背景的默认颜色:
<item name="android:actionBarItemBackground">@drawable/action_bar_item_background</item>
你尝试过这里用户3225831提到的解决方案吗:https://dev59.com/n2ct5IYBdhLWcg3wpO_H#21297231
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
使用简单的一行代码...传递所需颜色的RGB值
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.rgb(248, 248, 248)));
对于颜色代码,您可以使用这个网站: http://www.rapidtables.com/web/color/RGB_Color.htm
(注:该网站提供RGB、HEX和HSL颜色代码转换工具)styles.xml
文件中定义您的自定义主题,使用我问题中的代码,然后在AndroidManifest文件中使用它:
<application android:theme="@style/MyTheme" ...
- Tomasz