Search code examples
javaandroidxmlprogressdialogandroid-theme

Android Action Bar Text Custom Color


I am using a theme in styles.xml as below:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="colorPrimary">@color/md_blue_700</item>
    <item name="android:colorAccent">@color/md_blue_900</item>
    <item name="android:colorPrimaryDark">@color/md_blue_900</item>
    <item name="android:windowBackground">@color/md_white_1000</item>
    <item name="android:colorControlNormal">@color/md_blue_700</item>
    <item name="android:colorControlActivated">@color/md_blue_700</item>
    <item name="android:colorControlHighlight">@color/md_blue_700</item>
    <item name="android:textColorPrimary">@color/md_white_1000</item>
</style>

which I am declaring as android:theme in AndroidManifest.xml:

 <activity
        android:name=".LoginActivity"
        android:theme="@style/AppTheme"
        android:label="@string/activity_login_actionbar" />

The problem is highlighted in red in the image below.

Since I am setting

<item name="android:textColorPrimary">@color/md_white_1000</item>

to white the text in the progress bar also appears white and is invisible. If I change it to gray, the text in the action bar also changes to gray which I do not want.

I have tried things such as creating a seperate theme for the progress dialog but when I do that I lose the rounded corners of the dialog box and such.

This is my java code for creating the spinner:

progressDialog = new ProgressDialog(this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setTitle("Attempting Sign In");
progressDialog.setMessage("Please wait...");
progressDialog.setCancelable(false);

How should I go about solving this problem?

All answers appreciated!

enter image description here


Solution

  • You can use Theme.AppCompat.Light.DarkActionBar and remove <item name="android:textColorPrimary">@color/md_white_1000</item> in your theme style, then the title will become white. You can check the comparison between Light and Dark themes here

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/md_blue_700</item>
        <item name="android:colorAccent">@color/md_blue_900</item>
        <item name="android:colorPrimaryDark">@color/md_blue_900</item>
        <item name="android:windowBackground">@color/md_white_1000</item>
        <item name="android:colorControlNormal">@color/md_blue_700</item>
        <item name="android:colorControlActivated">@color/md_blue_700</item>
        <item name="android:colorControlHighlight">@color/md_blue_700</item>
    </style>