Custom progressdialog in android created dynamically
Asked Answered
S

1

7

I've created progressdialog in asynctask dynamically. I use custom style for my app. when I did that my progressdialog style changed to white color i need my default style in black with white text.

My java file:

class LoginTask extends AsyncTask<Void, Void, Void> {

private final ProgressDialog dialog = new ProgressDialog(Login.this);

@Override
protected void onPreExecute() {
    this.dialog.setMessage("Logging in...");
    this.dialog.show();
}

 // my prog

@Override
    protected void onPostExecute(Void result) {
        if (this.dialog.isShowing()) {
        this.dialog.dismiss();
        }}

My style.xml :

 <style name="AppBaseTheme" parent="android:Theme.Light">

</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="android:windowBackground">@drawable/blue</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:editTextColor">@color/white</item>
    <item name="android:buttonStyle">@android:style/Widget.Holo.Button</item>
    <item name="android:dropDownSpinnerStyle">@android:style/Widget.Holo.Spinner</item>
    <item name="android:textAppearanceButton">@android:style/TextAppearance.Widget.Button</item>
    <item name="android:progressBarStyle">@style/ProgressBar</item>

</style>
<style name="ProgressBar" parent="@style/android:Theme.Holo">
    <item name="android:textColor">@color/red</item>
    <item name="android:background">@color/green</item>
</style>

Shalloon answered 6/3, 2014 at 7:17 Comment(2)
then create another Theme for your Progress Dialog and set like ProgressDialog pd = new ProgressDialog(Activity.this, R.style.MyTheme);Dieback
Why this line is not working <item name="android:progressBarStyle">@android:style/Widget.ProgressBar</item>Shalloon
S
11

Change the below line to pass the style through your constructor...

private final ProgressDialog dialog = new ProgressDialog(Login.this);

to this...

private final ProgressDialog dialog = new ProgressDialog(Login.this, R.style.ProgressBar);

Update:

I just change the style as below...and its working for.

<style name="ProgressBar" parent="@style/android:Theme.Holo">
    <item name="android:textColor">#FFFFFF</item>
    <item name="android:background">#000000</item>
</style>
Schlueter answered 6/3, 2014 at 7:22 Comment(12)
I need default theme black backgroung and text in white. with this line. <item name="android:progressBarStyle">@android:style/Widget.ProgressBar</item>Shalloon
Now, which color you are getting?Schlueter
white backgorund and text.Shalloon
its working for me correctly...**White text and Black background**. Clean your project then run again.Schlueter
Yeah this way is working fine but y couldn't I use this way <item name="android:progressBarStyle">@android:style/Widget.Holo.ProgressBar</item>Shalloon
<item name="android:dropDownSpinnerStyle">@android:style/Widget.Holo.Spinner</item> This is working but not progressbarstyleShalloon
@HamidShatu Help me bro I'm stuck from yesterday.Shalloon
Why you are setting @color/red and @color/green when you are trying to set Wite and black?Schlueter
No change it. I want it like the one in holo themeShalloon
oh, man...I tried so hard...but could not achieve what you are desiring to do...I give up. Sorry buddy.Schlueter
No, it's not working. You get the default color and background, not what you set in the style.Emetic
@HamidShatu, I am trying run your snippet of code you mentioned above as i am trying to make a custom progressbar, I do get black background with white text, but progress dialog is shown at top - left corner of the screen, please tell me why this is so and is there a way to customize gravity of the custom progressbar as i want it to be at center of the screenSumerian

© 2022 - 2024 — McMap. All rights reserved.