如何在 Android 上制作任意颜色的加载指示器?

发布于 2024-11-13 05:11:32 字数 2457 浏览 4 评论 0原文

我有一个代码想要使用“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把回忆走一遍 2024-11-20 05:11:32

目前尚不完全清楚您要问什么,但我强烈建议您将 ProgressBar 定义放入其自己的 XML 布局中。 轻松应用样式

从那里,您可以通过添加属性 style="@style/NewDialog"例如 。创建 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>

然后在您的代码中执行以下操作:

dialog.setContentView(R.layout.progres);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文