【问题标题】:What's the default v7 compat theme for AlertDialogAlertDialog 的默认 v7 兼容主题是什么
【发布时间】:2014-12-31 18:42:16
【问题描述】:

在我的应用程序中,我使用Theme.AppCompat.Light.DarkActionBar 作为我的应用程序的基础。 当我创建 AlertDialog 时,我使用的是没有特定主题的创建它。 现在我想更新对话框中的一些颜色,但我不知道作为AlertDialog 的父级需要使用什么主题。 我试过Theme.Holo.DialogTheme.AppCompat.Light.Dialog 但没有。 谢谢

【问题讨论】:

    标签: android material-design android-alertdialog android-appcompat


    【解决方案1】:

    试试parent="@android:style/Theme.Dialog"

    【讨论】:

    • 不是。如果我为对话框强制使用此主题,则对话框会像姜饼一样显示,但我在棒棒糖中
    【解决方案2】:

    我自动回答问题...

    这是 v7 兼容轻主题的默认 Dialog 主题(它需要更新 Dialog 宽度(我不知道是什么原因)。

    @android:dimen/dialog_min_width_major @android:dimen/dialog_min_width_minor

    【讨论】:

      【解决方案3】:

      支持库(很遗憾)没有对话框主题,至少现在还没有。

      但是,有一些第三方库可以让您拥有材料设计对话框,例如AlertDailogPro

      【讨论】:

        【解决方案4】:

        有了新的AppCompat v22.1,您可以使用新的android.support.v7.app.AlertDialog

        只需使用这样的代码(当然,在您的情况下,您必须使用自定义布局才能拥有进度条)

        import android.support.v7.app.AlertDialog
        
        AlertDialog.Builder builder =
               new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
                    builder.setTitle("Dialog");
                    builder.setMessage("Lorem ipsum dolor ....");
                    builder.setPositiveButton("OK", null);
                    builder.setNegativeButton("Cancel", null);
                    builder.show();
        

        并使用这样的样式:

        <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
                <item name="colorAccent">#FFCC00</item>
                <item name="android:textColorPrimary">#FFFFFF</item>
                <item name="android:background">#5fa3d0</item>
            </style>
        

        【讨论】:

          猜你喜欢
          • 2022-07-19
          • 1970-01-01
          • 1970-01-01
          • 2012-06-03
          • 1970-01-01
          • 2023-02-14
          • 2012-03-02
          • 2013-07-26
          • 2020-09-11
          相关资源
          最近更新 更多