How to set style on progressBar programmatically on Android

I have a ProgressBar style in style.xml. When I create the layout, put a ProgressBar there and set the style as:

style="@style/ProgressBarStyle" 

set the layout to the dialog, and everything is in order.

Another way to create a dialog view is programmatically. So for ProgressBar I have the following code:

 new ProgressBar(context, null, R.style.ProgressBarStyle); 

But in this way there is nothing instead of the ProgressBar.

PS I do not forget to add a ProgressBar for viewing, which I set as a dialog box.

+7
android android styles
source share
2 answers

You can set the style from the constructor, for example:

 progressBar = new ProgressBar(activity, null, android.R.attr.progressBarStyleSmall); 

Where the third attribute is style.

In your case, I think the mistake is to choose the wrong one. Just this.

+8
source share

I know this is a late answer, but I found a solution myself.

To create a progress indicator with a style resource, you can do this by creating a layout file for the progress panel that has already set the style.

progressbar_default.xml

 <?xml version="1.0" encoding="utf-8"?> <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" style="@style/ProgressDialogStyle.Default"/> 

then you use the inflator from activity to create an indicator of progress.

 mProgressBar =(ProgressBar) getLayoutInflater().inflate(R.layout.progessbar_default,null); 
0
source share

All Articles