I'm trying to use a theme in my Toolbar. I want to change the text color but I can't do it, and I don't know why. The text color is not being applied, instead of be brown it appears me with black color. Can you please help me?
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>
you can set the Toolbar
title color programmatically
Random rnd = new Random();
ToolBar.setTitleTextColor(Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
This sets a random color, at runtime, you can add your preferred colour.
Color.RED
,Color.BLUE
etc.
THanks
You can use something like this:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With