【问题标题】:How to prevent AlertDialog using custom theme from appearing fullscreen?如何防止使用自定义主题的 AlertDialog 全屏显示?
【发布时间】:2016-08-01 05:19:05
【问题描述】:

我正在为我的AlertDialogs 使用自定义样式,但这会使它们显示为全屏。我四处搜索,但我似乎只能找到想要全屏的人......

这是我的风格

<style name="MyDialog" parent="AlertDialog.AppCompat">
    <item name="android:background">@color/material_dark</item>
    <item name="android:layout_height">100dp</item>
    <item name="android:textColor">@color/accent</item>
    <item name="android:textColorPrimary">@color/material_white</item>
</style>  

还有我的AlertDialogs 之一。

AlertDialog alertDialog = new AlertDialog.Builder(this.getContext(), R.style.MyDialog)
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setTitle(this.getContext().getResources().getString(R.string.reset) + "?")
            .setMessage(this.getContext().getResources().getString(R.string.AreYouSure))
            .setPositiveButton(getString(R.string.yes), (dialog, which) -> {
                reset();
            })
            .setNegativeButton(getString(R.string.notReally), (dialog, which) ->{
                //Do nothing
            })
            .show();

这就是它的样子。我无法弄清楚为什么它会占据整个屏幕。它应该看起来像 AlertDialog,只是带有自定义颜色。

【问题讨论】:

  • 确保wrap_content中reset.xml父布局的高度。
  • true 添加到您的样式中
  • @deepakjohn141 这成功了,非常感谢。
  • @WilliamSmith 很高兴为您提供帮助,我已将其添加为答案,请选择它作为答案
  • @deepakjohn141 gotchya

标签: android android-5.0-lollipop android-alertdialog android-styles presentation


【解决方案1】:
add <item name="android:windowIsFloating">true</item> to MyDialog style

【讨论】:

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