在 api 21 下将主题应用到对话框时出现奇怪的行为[重复]

2024-06-28

我正在使用主题"Theme.AppCompat.Light.NoActionBar"在我的应用程序中。 我想让我的一些对话框应用深色 AppCompat 主题。

所以,我为对话框创建了样式

 <style name="MyDialogStyle" parent="Theme.AppCompat.Dialog">

 </style>

(当父级是“Theme.AppCompat.Dialog.Alert”时,同样的问题) xml 文件中的一个,没有版本限制 以及 xml 文件中具有版本 api 21 约束的相同样式。 为了调用对话框,我使用了这个函数:

 public void showSimplestDialog(View view) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.MyDialogStyle);
    AlertDialog alertDialog = builder.setTitle("title")
            .setMessage("message ")
            .create();
    alertDialog.show();
}

api 21+ 中的结果看起来不错

但在 api 17 中,我得到了一些重复的背景,我无法摆脱它(即使当我尝试使用 builder.setView(MyView) 将自定义视图应用到对话框时


确保你必须import android.support.v7.app.AlertDialog这东西。

然后这样创建

AlertDialog.Builder builder =
       new AlertDialog.Builder(this, R.style.DialogStyle);
            builder.setTitle("Title");
            builder.setMessage("Abc ...");
            builder.setPositiveButton("OK", null);
            builder.setNegativeButton("Cancel", null);
            builder.show();

并在中创建样式styles.xml

<style name="DialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">#FFCC00</item>
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="android:background">#5fa3d0</item>
    </style>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 api 21 下将主题应用到对话框时出现奇怪的行为[重复] 的相关文章

随机推荐