简体   繁体   English

更改项目的操作栏文本颜色

[英]change the actionbar text color of an item

trying to change actionbar text color of this item in the action bar. 尝试在操作栏中更改此项目的操作栏文本颜色。 here is the item 这是项目

<item android:id="@+id/options_button"
        android:title="@string/options"
        android:showAsAction="ifRoom|withText"/>

and here is my styles.xml 这是我的styles.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="MyCustomTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBarTheme</item>
        <item name="android:background">@color/White</item>
        <item name="android:textColor">@color/Red</item>
    </style>

    <style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@color/White</item>
        <item name="android:textColor">@color/Red</item>
    </style>
</resources>

i saw other posts on here about this but after trying their solutions nothing worked for me? 我在这里看到了有关此的其他帖子,但是在尝试了他们的解决方案之后,对我没有任何帮助? is it something to do with how i made the theme? 这与我如何制作主题有关吗? All i really wanted was my action bar to be white, not display the title, and display a button that says options. 我真正想要的只是我的操作栏为白色,不显示标题,并显示一个显示选项的按钮。 I have all of that, but the options I want to be a red color im working with rather than black. 我拥有所有这些,但是我想使用的是红色而不是黑色。

dont think people understand... 不要以为人们了解...

I know of the way to change the title (I dont have a title and i dont want one).I want to change the color of the item that is displaying itself in the actionbar... 我知道更改标题的方法(我没有标题,我也不想一个)。我想更改在操作栏中显示自身的项目的颜色...

I have faced the same issue, but I found a solution that doing well with any type of ActionBar (Native, Sherlock or Compat) 我遇到过同样的问题,但是我找到了一种解决方案,可以与任何类型的ActionBar(本机,Sherlock或Compat)配合使用

Actually you can use HTML code to set the title, and specify the text color. 实际上,您可以使用HTML代码设置标题,并指定文本颜色。 For example, to set the ActionBar text color to red, simply do this: 例如,要将ActionBar文本颜色设置为红色,只需执行以下操作:

getActionBar()/* or getSupportActionBar() */.setTitle(Html.fromHtml("<font color=\"red\">" + getString(R.string.app_name) + "</font>"));

You can also use hex code of red color #FF0000 instead of the word red . 您也可以使用红色#FF0000十六进制代码代替单词red

But, Setting a HTML string on the action bar doesn't work on the Material theme in SDK v21+. 但是,在操作栏上设置HTML字符串不适用于SDK v21 +中的Material主题。

If you want to change it you should set the primary text color in your style.xml as below. 如果要更改它,则应在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>

May this helps you. 可能对您有帮助。

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

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