我正在尝试显示一个AlertDialog
,可以通过后退按钮或触摸对话框外部将其关闭。那里有很多解决方案,我知道哪一个是正确的解决方案,因为我之前使用过它。但是现在我无法实现。这是我的代码:
AlertDialog alertDialog = new AlertDialog.Builder(activity, R.style.AppTheme_Dark_Dialog).create();
//Some setup of the dialog...
...
//This works when I press the back button
alertDialog.setCancelable(true);
//This should be the right answer of my problem
alertDialog.setCanceledOnTouchOutside(true);
alertDialog.show();
据我所知,通过使用真实参数值调用此方法就足够了:
alertDialog.setCanceledOnTouchOutside(true);
但是不会起作用。有人可以启发我吗?
编辑:
样式<style name="AppTheme.Dark.Dialog" parent="Theme.AppCompat.Dialog">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/white</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:textColor">@color/white</item>
<item name="android:background">@color/primary</item>
</style>
我正在尝试显示一个AlertDialog,可以通过后退按钮或触摸对话框外部将其关闭。那边有很多解决方案,我知道哪个是正确的,因为我用了它...
删除