[英]Actionbar Compat change title textColor
I am trying to modify the text color of the title of the ActionBarSupport. 我试图修改ActionBarSupport标题的文本颜色。 I have used ActionBarStyleGenererator to create a theme with the correct colors and it works well.
我已经使用ActionBarStyleGenererator来创建一个具有正确颜色的主题,并且效果很好。
While using the light theme, I would like to change the color of the heading to white (in the genererator I cannot set the text color(. For a number of reasons I cannot use the dark actionbar theme. I am so close, just have to get the title to white ;-) 在使用灯光主题时,我想将标题的颜色更改为白色(在发布者中我无法设置文本颜色(。由于多种原因,我无法使用黑暗的动作栏主题。我非常接近,只是有得到白色的标题;-)
What I am doing wrong here? 我在这做错了什么?
<style name="ActionBar.Transparent.MyApp" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="background">@drawable/ab_transparent_myapp</item>
<item name="progressBarStyle">@style/ProgressBar.MyApp</item>
<item name="titleTextStyle">@style/MyApp.TitleTextStyle</item>
</style>
<style name="MyApp.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.Base.ActionBar.Title">
<item name="android:textColor">#ffffff</item>
</style>
The below code worked for me. 以下代码对我有用。 I hope it will help you tooo.
我希望它能帮助你。
<style name="AppTheme" parent="AppBaseTheme">
<item name="actionBarStyle">@style/ActionBarCompat</item>
</style>
<style name="ActionBarCompat" parent="@style/Widget.AppCompat.Base.ActionBar">
<item name="titleTextStyle">@style/titleStyle</item>
</style>
<style name="titleStyle" parent="@style/TextAppearance.AppCompat.Widget.Base.ActionBar.Title">
<item name="android:textColor">@android:color/white</item>
</style>
Embarrassing. 尴尬。 I was not paying attention to the values-v14/-folder (which overrides the vales/) ActionBarStyleGenererator created.
我没注意创建的值-v14 / -folder(覆盖vales /)ActionBarStyleGenererator。 Using the android-prefix on the styles in values-v14 it worked:
在values-v14中使用样式的android-prefix工作:
<item name="android:titleTextStyle">@style/titleTextStyle</item>
Found at Overflow styling 发现溢流造型
I've been trying to keep the ActionBar title text color through orientation changes without much luck until I got a clue from the above site. 我一直试图通过方向更改保持ActionBar标题文本颜色,没有太多运气,直到我从上面的网站得到一个线索。 I applied the Spannable to to the title.
我将Spannable应用于标题。 Here's what i do when setting up my ActionBar:
这是我在设置ActionBar时所做的事情:
Spannable actionBarTitle = new SpannableString("Action Bar Title");
actionBarTitle.setSpan(
new ForegroundColorSpan(Color.WHITE),
0,
actionBarTitle.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mActionBar.setTitle(actionBarTitle);
This needs to be executed on orientation change. 这需要在方向改变时执行。 I call it from onCreate()...don't know if it works in onConfigurationChange().
我从onCreate()调用它...不知道它是否在onConfigurationChange()中有效。
@TNR is correct, however you should double check if your layout xml file has not overriden the android:theme
attribute with a different style. @TNR是正确的,但是你应该仔细检查你的布局xml文件是否没有用不同的样式覆盖
android:theme
属性。
This usually happens if you have generated layout files 如果生成了布局文件,通常会发生这种情况
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.