Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为progressDialog设置常规主题?_Android - Fatal编程技术网

Android 为progressDialog设置常规主题?

Android 为progressDialog设置常规主题?,android,Android,如何为我在项目中创建的所有进度条设置主题 这是我的风格: <style name="MyTheme.ProgressDialog" parent="android:Theme.Holo.Light.Dialog.NoActionBar"> <item name="android:textColor">@android:color/anyColor</item> <item name="android:windowBackground"&g

如何为我在项目中创建的所有进度条设置主题

这是我的风格:

<style name="MyTheme.ProgressDialog" parent="android:Theme.Holo.Light.Dialog.NoActionBar">
    <item name="android:textColor">@android:color/anyColor</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

我是否可以将主题设置为我创建的所有进度对话框的默认值,而不必每次在构造函数中对其进行更改?

ProgressDialog
只有一个构造函数内部使用
com.android.internal.R.style.theme\u Dialog\u Alert
样式。你没办法覆盖它。相比之下,您可以创建ProgressDialog的一个简单子类,并使用它创建一个将使用您的样式的构造函数。这样,您就不必每次都指定样式

public class MyProgressDialog extends ProgressDialog {
    public MyProgressDialog(Context context) {
        super(context, R.style.your_custom_style);
    }

    public MyProgressDialog(Context context, int theme) {
        super(context, theme);
    }
}

在style.xml中设置进度样式,如下所示:

<style name="progressBar" parent="android:Widget.Holo.ProgressBar.Large">
<item name="android:progressBarStyle">@android:style/Widget.Holo.Light.ProgressBar.Large</item>
</style>

@android:style/Widget.Holo.Light.ProgressBar.Large
然后在所有progressbars中设置样式属性,如下所示:

  <ProgressBar
        android:id="@+id/loading_spinner_1"
        style="@style/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="gone" />


请注意,这样您只需设置
ProgressBar
的样式,而
ProgressDialog
不仅仅包含
ProgressBar
。您是对的,这个答案对于ProgressBar是正确的。仍然是一个没有重复的新帐户。。。对不起:D
  <ProgressBar
        android:id="@+id/loading_spinner_1"
        style="@style/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="gone" />