繁体   English   中英

如何使用样式设置操作栏标题的文本颜色

[英]How to set the text color of action bar title using style

您好,我正在尝试将ActionBar标题颜色设置为White。 我尝试了下面的代码,但是没有用。 目前标题显示为黑色。 我不知道我在想什么。 我尝试了许多不同的尝试,但没有成功,其他属性也能正常工作,例如背景色等。

我正在使用AppCompat库进行反向移植。

谁能帮我。

style.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light">

        <!-- colorPrimary is used for the default action bar background -->
        <item name="colorPrimary">@color/my_awesome_color</item>

        <!-- colorPrimaryDark is used for the status bar -->
        <item name="colorPrimaryDark">@color/my_awesome_dark_color</item>

        <!-- colorAccent is used as the default value for colorControlActivated,
            which is used to tint widgets -->
        <item name="colorAccent">@color/accent</item>

        <!-- ActionBar Text Style -->
        <item name="titleTextStyle">@style/titleStyle</item>

    </style>

    <style name="ActionBarCompat" parent="Widget.AppCompat.ActionBar">
        <item name="atitleTextStyle">@style/titleStyle</item>



    </style>

    <style name="titleStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/action_bar_text_color</item>
    </style>

</resources>

如果您使用的是工具栏,则可以使用以下代码:

<android.support.v7.widget.Toolbar
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res/it.onecalculator"
  android:id="@+id/toolbar"
  android:layout_width="match_parent"
  android:layout_height="?attr/actionBarSize"
  android:background="?attr/colorPrimary"
  app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
  app:titleTextAppearance="@style/MyActionBarTitleText" />

其中MyActionBarTitleText为:

<style name="MyActionBarTitleText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
   <item name="android:textColor">@color/white</item>       
</style>

暂无
暂无

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

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