【问题标题】:Style MaterialDialog not being applied样式 MaterialDialog 未应用
【发布时间】:2017-04-22 14:37:30
【问题描述】:

我正在尝试为(材质)对话框设置 自定义样式,但它没有被应用,它只显示默认(白色)。

我已经检查了一些来源并用谷歌搜索,但不知何故我没有得到我想要的结果。

请注意,我是造型新手。如果有人可以帮助我,我将不胜感激。

谢谢。

MyAlertDialogStyle:

<style name="MyAlertDialogStyle" parent="@android:style/Theme.Dialog">
   <!-- Used for the buttons -->
   <item name="colorAccent">#FFC107</item>
   <!-- Used for the title and text -->
   <item name="android:textColorPrimary">#FFFFFF</item>
   <!-- Used for the background -->
   <item name="android:background">#4CAF50</item>
</style>

Utils.class 创建对话框的位置:

public static MaterialDialog createDarkLoadingDialog(Activity activity, int myAlertDialogStyle) {
        return new MaterialDialog.Builder(activity)
                .title(R.string.loading)
                .content(R.string.wait)
                .progress(true, 0)
                .cancelable(false)
                .build();
    }

我显示对话框的Activity

public class ConversationDetailActivity extends BaseActivity implements LoaderManager.LoaderCallbacks<BaseResponse> {

MaterialDialog pd;
..
pd = Utils.createDarkLoadingDialog(this, R.style.MyAlertDialogStyle);
pd.show();
..
}

【问题讨论】:

    标签: android dialog styles


    【解决方案1】:

    对于任何有同样问题的人,我通过使用 contextwrapper 解决了它。

    public static MaterialDialog createDarkLoadingDialog(Activity activity) {
            ContextThemeWrapper ctw = new ContextThemeWrapper(activity, R.style.MyAlertDialogStyle);
            return new MaterialDialog.Builder(ctw)
                    .title(R.string.loading)
                    .content(R.string.wait)
                    .progress(true, 0)
                    .cancelable(false)
                    .build();
        }
    

    然后只需在您的活动中调用/显示对话框:

    pd = Utils.createDarkLoadingDialog(this);
    pd.show();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2016-02-28
      相关资源
      最近更新 更多