Android:工具栏文本颜色



我正试图在工具栏中使用一个主题。我想更改文本颜色,但我做不到,也不知道为什么。文本颜色没有被应用,它不是棕色,而是黑色。你能帮帮我吗?

styles.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    </style>
    <style name="AppTheme.Toolbar.Title" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
        <!-- Set proper title size -->
        <item name="android:textSize">@dimen/abc_text_size_title_material_toolbar</item>
        <item name="android:gravity">center</item>
        <item name="android:textColor">@color/brown</item>
    </style>
</resources>

layout.xml

<android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:background="@drawable/toolbar_main"
        style="@style/AppTheme.Toolbar.Title">    
    </android.support.v7.widget.Toolbar>

colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="brown" type="color">#b78c07</item>
    <integer-array name="androidcolors">
        <item>@color/brown</item>
    </integer-array>
</resources>

您可以通过程序设置Toolbar标题颜色

Random rnd = new Random(); 
ToolBar.setTitleTextColor(Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));

这设置了一个随机的颜色,在运行时,你可以添加你喜欢的颜色。Color.REDColor.BLUE

THanks

您可以使用这样的东西:

<android.support.v7.widget.Toolbar
  app:theme="@style/MyToolbar" />

<style name="MyToolbar" parent="Theme.AppCompat.NoActionBar">
  <!-- android:textColorPrimary is the  color of the title text
     in the Toolbar, in the Theme.AppCompat theme:  -->
  <item name="android:textColorPrimary">@color/my_color</item>
  <!-- android:textColorPrimaryInverse is the  color of the title
       text in the Toolbar, in the Theme.AppCompat.Light theme:  -->
 <item name="android:textColorPrimaryInverse">@color/my_color</item>
</style>

最新更新