如何在 Android 上制作任意颜色的加载指示器?
我有一个代码想要使用“Style.xml”,因为我在最后显示文件内容。我想要做的是“ ProgressDailog Indicator 更改其颜色,该颜色将在 Style.xml 中定义......简单。
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);
}
}
这里是样式。我只想修改 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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前尚不完全清楚您要问什么,但我强烈建议您将
ProgressBar
定义放入其自己的 XML 布局中。 轻松应用样式从那里,您可以通过添加属性
style="@style/NewDialog"
例如 。创建progress.xml
:然后在您的代码中执行以下操作:
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 attributestyle="@style/NewDialog"
eg. create
progress.xml
:And then in your code, do: