【问题标题】:ProgressDialog with custom theme带有自定义主题的 ProgressDialog
【发布时间】:2017-10-08 01:02:21
【问题描述】:

我有一个与主题相关联的活动(在 AndroidManifest.xml 中)

<activity
        android:name=".BenchTestActivity"
        android:parentActivityName=".HomeActivity"
        android:theme = "@style/AppTheme.CaeTheme">

AppTheme.CaeTheme 不包含任何内容(目前),但 AppTheme 是:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:background">@color/colorPrimary</item>
</style>

(colorPrimary 为深蓝色)

现在我在上述活动中定义了一个progressDialog。

progressDialog = new ProgressDialog(BenchTestActivity.this);
progressDialog.setProgressStyle(R.style.ProgressDialog);

这里是 ProgressDialog 样式:

<style name="ProgressDialog">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:layout_centerHorizontal">true</item>
    <item name="android:layout_centerVertical">true</item>
    <item name="android:visibility">gone</item>
</style>
<style name="CustomAlertDialogStyle">
    <item name="android:background">@color/colorBackgroundProgressDialog</item>
    <item name="android:textColorPrimary">#e6e6e6</item>
</style>

colorBackgroundProgressDialog 是浅灰色。我期待获得该颜色作为我的进度对话框的背景,但事实并非如此(背景颜色是深蓝色,colorPrimary)。因此,活动主题的背景是获胜的。那么,如何为进度对话框设置自定义颜色?

提前致谢。

【问题讨论】:

  • 是的,由于活动应用的主题,请再次检查
  • 我知道。但是我怎样才能正确设置呢?我需要活动的主题。自定义progressDialog的背景有什么方法?

标签: java android android-layout android-view progressdialog


【解决方案1】:

使用accepts theme as argument的构造函数并传递适当的主题。

ProgressDialog progressDialog = new ProgressDialog(context, R.style.MyProgressDialogTheme); progressDialog.show();

styles.xml:

<style name="MyProgressDialogTheme" parent="ThemeOverlay.AppCompat.Dialog.Alert">
    <!-- override attributes here -->
</style>

【讨论】:

  • @Massimo,很可能您应用了不正确的主题。更新答案,检查,按预期工作。
  • 不,使用这个构造函数progressDialog 不会出现。我不知道为什么但是...这对progressDialog = new ProgressDialog(BenchTestActivity.this); progressDialog.setProgressStyle(R.style.ProgressDialog);应该是一样的。但是,正如我在回答中所说,这种风格不会覆盖活动的主题。
  • should be the same 不一样。
  • 好的。导致错误的原因是标签 gone。删除它并开始工作。
【解决方案2】:

在你的 style.xml 中

<style name="Custom" parent="android:Theme.DeviceDefault.Dialog">
    <item name="DialogTitleAppearance">@android:style/TextAppearance.Medium</item>
    <item name="DialogTitleText">Loading……</item>  
    <item name="DialogSpotColor">@android:color/holo_orange_dark</item>
    <item name="DialogSpotCount">4</item>
</style>

在你的活动中,java:

SpotsDialog spotsDialog = new SpotsDialog(Context,R.style.Custom);
spotsDialog.show();  //where you want
spotsDialog.dismiss(); //where you want

并添加依赖

compile 'com.github.d-max:spots-dialog:0.7@aar'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 1970-01-01
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多