如何更改动作栏的文本颜色?我继承了Holo光主题,我能够改变动作栏的背景,但我不知道什么是属性调整来改变文本颜色。


好,我能够改变文本颜色与属性android:textColorPrimary但它也改变了文本颜色的下拉菜单显示时,溢出发生在动作栏按钮。知道如何改变那些下拉菜单/列表的颜色吗?


当前回答

我和你有同样的问题,是Holo。轻主题,但我想样式的动作栏的颜色,所以我需要改变文本的颜色以及标题和菜单。所以最后我去了git中心,查看源代码,直到我找到了该死的正确风格:

<?xml version="1.0" encoding="utf-8"?>
<!-- For honeycomb and up -->
<resources>

    <style name="myTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/myTheme.ActionBar</item>
        <item name="android:actionMenuTextColor">@color/actionBarText</item>
    </style>

    <style name="myTheme.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@drawable/actionbarbground</item>
        <item name="android:titleTextStyle">@style/myTheme.ActionBar.Text</item>
    </style>

    <style name="myTheme.ActionBar.Text" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/actionBarText</item>
    </style>

</resources>

所以现在你要做的就是设置任何@color/actionBarText and@drawable/actionbarbground你想要!

其他回答

这里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

很多答案已弃用,所以我将更新线程,并展示如何在ActionBar(工具栏)和ActionBar弹出菜单中更改文本颜色和背景色。

在Android中(截至2018年5月)使用操作栏(工具栏)的最新方法是使用主题和NoActionBar,而不是使用工具栏。

这就是你所需要的:

In Activity (which extends AppCompatActivity) declare Toolbar: Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(myToolbar); Add Toolbar in the Activity's layout xml. Here we will set our custom (overwritten themes), note android:theme="@style/ThemeOverlay.AppTheme.ActionBar" and app:popupTheme="@style/ThemeOverlay.AppTheme.PopupMenu", they will do the trick. <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" android:theme="@style/ThemeOverlay.AppTheme.ActionBar" app:popupTheme="@style/ThemeOverlay.AppTheme.PopupMenu" app:layout_constraintTop_toTopOf="parent" /> In your styles.xml you will have to overwrite those two styles to set custom colors: <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="actionBarTheme">@style/ThemeOverlay.AppTheme.ActionBar</item> <item name="actionBarPopupTheme">@style/ThemeOverlay.AppTheme.PopupMenu</item> </style> <style name="ThemeOverlay.AppTheme.ActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> <item name="android:textColorPrimary">@color/action_bar_text_color</item> <item name="android:background">@color/action_bar_bg_color</item> </style> <style name="ThemeOverlay.AppTheme.PopupMenu" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> <item name="android:background">@color/popup_bg_color</item> <item name="android:textColorPrimary">@color/popup_text_color</item> </style>

就是这样,伙计们

附注:如果你问我,我会说:是的,整个主题的事情是一团糟。

我和你有同样的问题,是Holo。轻主题,但我想样式的动作栏的颜色,所以我需要改变文本的颜色以及标题和菜单。所以最后我去了git中心,查看源代码,直到我找到了该死的正确风格:

<?xml version="1.0" encoding="utf-8"?>
<!-- For honeycomb and up -->
<resources>

    <style name="myTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/myTheme.ActionBar</item>
        <item name="android:actionMenuTextColor">@color/actionBarText</item>
    </style>

    <style name="myTheme.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@drawable/actionbarbground</item>
        <item name="android:titleTextStyle">@style/myTheme.ActionBar.Text</item>
    </style>

    <style name="myTheme.ActionBar.Text" parent="@android:style/TextAppearance">
        <item name="android:textColor">@color/actionBarText</item>
    </style>

</resources>

所以现在你要做的就是设置任何@color/actionBarText and@drawable/actionbarbground你想要!

最直接的方法是在styles.xml中完成。

谷歌的模板styles.xml当前生成以下内容:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

如果你在结束标签之前再添加一行,如图所示,这将改变文本的颜色,使其与Dark ActionBar相同:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- 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/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

如果你想自定义颜色为其他东西,你可以在colors.xml中指定自己的颜色,甚至使用Android的内置颜色使用Android:textColorPrimary属性:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- 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/AppTheme.AppBarOverlay</item>
</style>


<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:textColorPrimary">@android:color/darker_gray</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>