简体   繁体   English

Android 4 ActionBar-使用Action Bar Sherlock时更改textColor

[英]Android 4 ActionBar - changing textColor when using Action Bar Sherlock

I am using the ActionBarSherlock and almost everything seems to work fine. 我正在使用ActionBarSherlock,几乎所有功能都可以正常工作。 But I want the title text color in white. 但是我想要标题文本为白色。 When using the Sherlock-Actionbar it works fine but not with the original ActionBar in Android 4 使用Sherlock-Actionbar时,效果很好,但不能与Android 4中的原始ActionBar一起使用

In an act of desperation I tried this: 在无奈之下,我尝试了以下方法:

 <style name="Widget.AppTheme.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
        <item name="titleTextStyle">@style/TextAppearance.AppTheme.Widget.ActionBar.Title</item>
        <item name="android:gravity">center</item>

        <item name="android:background">@color/white</item>
        <item name="android:textColor">@color/white</item>
</style>

and found that the background changed as told to white. 并发现背景变成了白色。 So this is obviously the right place to change. 因此,这显然是更改的正确位置。 But still changing the textColor to white doesn't work for me. 但是仍然将textColor更改为白色对我不起作用。

I'm using this as my Theme: 我使用它作为我的主题:

<style name="AppTheme" parent="Theme.Sherlock.Light">
        <item name="android:actionBarStyle">@style/Widget.AppTheme.ActionBar</item>
        <item name="actionBarStyle">@style/Widget.AppTheme.ActionBar</item>

        <item name="textColorPrimary">@color/white</item>
        <item name="android:textColor">@color/white</item>
        ...
</style>

So any idea what could be the problem? 那么任何想法可能是什么问题? Why is it working with the background but not with the textColor? 为什么它与背景一起使用而不与textColor一起使用?

Thanks, Tobias 谢谢托比亚斯

--- EDIT FROM HERE --- -从这里编辑-

I just found out that if I use my theme programmaticall like 我刚刚发现,如果我使用主题程序,

setTheme(R.style.Widget_AppTheme_ActionBar);

It works. 有用。 But if I rely on the settings I have in my Manifest it doesn't. 但是,如果我依赖清单中的设置,则不会。

<application ... android:theme="@style/AppTheme" >

but

<application ... android:theme="@style/Widget_AppTheme_ActionBar" >

would do fine - even though the other styles from the AppTheme wouldn't be set. 会很好-即使不会设置AppTheme中的其他样式。 So it looks like using a theme that defines an own ActionBarStyle doesn't work. 因此,似乎无法使用定义自己的ActionBarStyle的主题。

Has anyone any idea? 有人知道吗?

Okay, sorry for answering my own question. 好的,很抱歉回答我自己的问题。 I eventually realized my problem. 我终于意识到了我的问题。 Of cause I have to use these two arguments 当然,我必须使用这两个参数

<item name="titleTextStyle">@style/TextAppearance.AppTheme.Widget.ActionBar.Title</item>
<item name="android:titleTextStyle">@style/TextAppearance.AppTheme.Widget.ActionBar.Title</item>

Since the first one is working for Android 2.x with the ActionBarSherlock and the second one is doing the same for the native Action Bar. 由于第一个在ActionBarSherlock上适用于Android 2.x,第二个在本机Action Bar上也是如此。

I hope this helps someone who has the same trouble as I had. 我希望这对遇到和我一样麻烦的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM