Android 如何获得MaterialAlertDialog当前背景色
我有两个重叠的视图,可以查看我的MaterialAlertDialog以进行刷卡。Android 如何获得MaterialAlertDialog当前背景色,android,material-design,Android,Material Design,我有两个重叠的视图,可以查看我的MaterialAlertDialog以进行刷卡。 如果用户滑动,您将看到下方视图 因此,我需要为顶视图设置与MaterialAlertDialog背景相同的背景色。 如何获取当前MaterialAlertDialog的背景色 将此样式用于我的黑色主题: Theme.MaterialComponents.Dialog.Alert 对于这种风格的灯光主题: Theme.MaterialComponents.Dialog.Alert 主主题父项也是明暗相间的材质:
如果用户滑动,您将看到下方视图 因此,我需要为顶视图设置与MaterialAlertDialog背景相同的背景色。
如何获取当前MaterialAlertDialog的背景色 将此样式用于我的黑色主题:
Theme.MaterialComponents.Dialog.Alert
对于这种风格的灯光主题:
Theme.MaterialComponents.Dialog.Alert
主主题父项也是明暗相间的材质:
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.NoActionBar
已经尝试过
?android:attr/background
,但这与物料警报对话框的背景颜色不同:-(首先,您可以使用样式设置alerDialog。代码如下所示:
<style name="AlertDialogTheme" parent="Theme.MaterialComponents.Light.Dialog.Alert">
<item name="buttonBarPositiveButtonStyle">@style/Alert.Button.Positive</item>
<item name="buttonBarNegativeButtonStyle">@style/Alert.Button.Neutral</item>
<item name="buttonBarNeutralButtonStyle">@style/Alert.Button.Neutral</item>
</style>
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(context, R.style.AlertDialogTheme))
我建议您设置自定义主题谢谢您提供的信息。我知道AlertDialogTheme,并且我已经使用过它,但是我找不到材质警报对话框背景色的属性。我尝试了代码,但最好直接在视图上使用属性。您知道用于材质AlertDialogba的属性吗ckground?@chrisonline,在第二种解决方案中,我给出了源代码。您可以查找它。我在背景上找到了一个
@color/design\u dark\u default\u color\u attrs。已经尝试了该属性和许多其他属性。它们与背景的颜色不是100%相同:-(
alertDialog.getWindow().getDecorView().getBackground()