Search code examples
androidandroid-themeandroid-toolbar

Change title color in toolbar?


I have a toolbar that I use, and set title with:

((ActionBarActivity)getActivity()).getSupportActionBar().setTitle("Home");

Is there a way to change the color from black to white?

I tried making its own theme and setting it in the xml like this, but no dice:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme2" parent="Theme.AppCompat">
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:textColorPrimary">@color/primary_text</item>
        <item name="android:textColorSecondary">@color/secondary_text</item>

    </style>

    <style name="Widget.MyApp.ActionBar" parent="Widget.AppCompat.ActionBar">
        <item name="android:background">@color/primary</item>
        <item name="theme">@style/ThemeOverlay.MyApp.ActionBar</item>
        <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
    </style>

    <style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar">
        <item name="android:textColorPrimary">#FFFFFF</item>
    </style>



</resources>

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#e5e5e5"
    android:orientation="vertical" >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/primary"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/Widget.MyApp.ActionBar">

        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/statsSpin"
            android:spinnerMode="dropdown"
            android:textColor="#FFFFFF"/>


    </android.support.v7.widget.Toolbar>



    <ListView
        android:id="@+id/yourStats"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:dividerHeight="0px"
        android:divider="@null"

        >
    </ListView>



</LinearLayout>

Solution

  • Programatically:

    toolbar.setTitleTextColor(0xFFFFFFFF);