如何更改动作栏的文本颜色?我继承了Holo光主题,我能够改变动作栏的背景,但我不知道什么是属性调整来改变文本颜色。
好,我能够改变文本颜色与属性android:textColorPrimary但它也改变了文本颜色的下拉菜单显示时,溢出发生在动作栏按钮。知道如何改变那些下拉菜单/列表的颜色吗?
如何更改动作栏的文本颜色?我继承了Holo光主题,我能够改变动作栏的背景,但我不知道什么是属性调整来改变文本颜色。
好,我能够改变文本颜色与属性android:textColorPrimary但它也改变了文本颜色的下拉菜单显示时,溢出发生在动作栏按钮。知道如何改变那些下拉菜单/列表的颜色吗?
当前回答
在操作栏上设置HTML字符串在SDK v21+的Material主题上不起作用
如果你想改变它,你应该在style.xml中设置主文本颜色
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Customize your theme here. -->
<item name="android:textColorPrimary">@color/actionbar-text-color</item>
</style>
</resources>
其他回答
这里style。xml就像
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="actionBarTheme">@style/MyTheme</item>
</style>
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="AppTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">@color/colorBlack</item>
</style>
你应该加上
<item name="actionBarTheme">@style/MyTheme</item>
在AppTheme
找到了一种方法,可以很好地做到这一点,而无需在API >= 21上创建自己的布局。
它只会在操作栏中对文本和控件绘图进行着色。
希望对别人有用。
<!--Material design primary colors-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:navigationBarColor">@color/primary_dark</item>
<item name="actionBarTheme">@style/AppBaseTheme.Toolbar</item>
</style>
<!--Action bar-->
<style name="AppBaseTheme.Toolbar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="android:textColorPrimary">@color/action_bar_text</item>
<item name="colorControlNormal">@color/action_bar_text</item>
</style>
尝试了很多方法,在低版本的API中,一个可行的方法是<item name="actionMenuTextColor">@color/your_color</item>,不要使用Android命名空间,希望可以帮助到你
ps:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="actionMenuTextColor">@color/actionMenuTextColor</item>
</style>
在操作栏上设置HTML字符串在SDK v21+的Material主题上不起作用
如果你想改变它,你应该在style.xml中设置主文本颜色
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Customize your theme here. -->
<item name="android:textColorPrimary">@color/actionbar-text-color</item>
</style>
</resources>
我已经用简单的一行代码完成了
actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBartitle </font>"));