Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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> 
like image 485
Mike Avatar asked Mar 10 '15 01:03

Mike


People also ask

How do I change the color of my toolbar title?

Go to the app > res > values > themes > themes. xml file and add the following line inside the <resources> tag. In the activity's onCreate() method, call the activity's setSupportActionBar() method, and pass the activity's toolbar. This method sets the toolbar as the app bar for the activity.

How do you change the color of your toolbar on Android?

Just go to res/values/styles.edit the xml file to change the color of action bar. Code for styles.


1 Answers

Programatically:

toolbar.setTitleTextColor(0xFFFFFFFF); 
like image 56
tachyonflux Avatar answered Oct 04 '22 12:10

tachyonflux