aguyngueran
aguyngueran

Reputation: 1321

Android indeterminate progress dialog progress bar style

I cannot find the reason why the style of progress bar shown inside indeterminate ProgressDialog differs between Android 22 and 23.

Let's take a very simple layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="example.com.progressbarcolor.MainActivity">

    <Button
        android:id="@+id/show_progress"
        android:text="Show progres"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>

    <ProgressBar
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true"
        android:indeterminate="true"
        android:visibility="visible"/>
</RelativeLayout>

Pressing the button displays ProgressDialog:

ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();

The style of the app is:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

And finally the gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "example.com.progressbarcolor"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
}

As you can see on the images below both apps display the same progress bar when used directly inside layout but the colors are different inside ProgressDialog.

On Android 22, the progress dialog shows green progress bar instead of red one.

Nexus 5, API 22

Nexus 5 - API 22

Nexus 5X, API 23

Nexus 5X - API 23

Upvotes: 2

Views: 5305

Answers (1)

Pradeep Gupta
Pradeep Gupta

Reputation: 1770

Add this in Your Style :

<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog">
        <!-- Used for the buttons -->
        <item name="colorAccent">@color/colorAccent</item>
        <!-- Used for the title and text -->
        <item name="android:textColorPrimary">@color/colorPrimaryDark</item>
        <!-- Used for the background -->
        <item name="android:background">@android:color/transparent</item>
    </style>

and set to the dialog :

ProgressDialog progressDialog = new ProgressDialog(MainActivity.this, R.style.MyAlertDialogStyle);

Upvotes: 5

Related Questions