簡體   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