How I can make a loading indicator with any color on android?
I have a code want to user "Style.xml" as I show file content at the end. What I want to do is " The ProgressDailog Indicator开发者_开发技巧 to change its color which will be defined in Style.xml.... Simple.
public class SimpleProgressDialog extends Dialog {
public static SimpleProgressDialog show(Context context, CharSequence title,
CharSequence message) {
return show(context, title, message, false);
}
public static SimpleProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate) {
return show(context, title, message, indeterminate, false, null);
}
public static SimpleProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate, boolean cancelable) {
return show(context, title, message, indeterminate, cancelable, null);
}
public static SimpleProgressDialog show(Context context, CharSequence title,
CharSequence message, boolean indeterminate,
boolean cancelable, OnCancelListener cancelListener) {
SimpleProgressDialog dialog = new SimpleProgressDialog(context);
dialog.setTitle(title);
dialog.setCancelable(cancelable);
dialog.setOnCancelListener(cancelListener);
/* The next line will add the ProgressBar to the dialog. */
dialog.addContentView(new ProgressBar ( context , null ,android.R.attr.progressBarStyleLargeInverse ), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
dialog.show();
return dialog;
}
public SimpleProgressDialog(Context context) {
super(context, R.style.NewDialog);
}
}
here is style. I want to modify just style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- The style for the unit on the statistics activity. -->
<style name="NewDialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">@android:color/transparent</item>
</style>
It's not entirely clear what you're asking, but I highly recommend putting you ProgressBar
definition in its own XML layout. From there, you can easily apply the style by adding the attribute style="@style/NewDialog"
eg. create progress.xml
:
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/progress"
style="@style/NewDialog"
>
</ProgressBar>
And then in your code, do:
dialog.setContentView(R.layout.progres);
精彩评论