Changing ActionBar Text and Button color when using Theme.AppCompat.Light

1k views Asked by At

This is my styles.xml file and the theme I am using AppTheme2:

<?xml version="1.0" encoding="utf-8"?>

<!-- Base application theme. -->
<style name="AppTheme2" parent="Theme.AppCompat.Light">
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#FF5722</item>
    <!--<item name="android:statusBarColor">#E64A19</item>-->

    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#E64A19</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>

    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#FF9800</item>

    <item name="android:textColor">#fff</item>



    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight & colorSwitchThumbNormal. -->

</style>

I prefer to use Theme.AppCompat.Light because this changed the color of my navigation drawer to white as desired but unfortunately changed the color of the buttons and text in the action bar to black and I just want them to be white. How can I accomplish this?

(The android:textColor field has no effect, and removing "android" from it causes an xml error when compiling)

3

There are 3 answers

0
tachyonflux On

textColorPrimary effects the action bar text:

<item name="android:textColorPrimary">#fff</item>

Alternatively, inheriting from DarkActionBar Theme will use white text in the action bar:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
0
ez4nick On

The theme Theme.AppCompat.Light.DarkActionBar was exactly what I needed to use. Solved my problem!

0
B.shruti On

You must use below theme for achieving title text color and back button color to white.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

This theme would by default change it.