Android Kotlin 中的自定义警报对话框
Custom Alertdialog In Android Kotlin
我尝试将 Alertdialog 中的文本和背景颜色更改为白色文本和透明背景。但是,它没有用。
请参阅下文,让我知道我错过了什么。谢谢。
注意:Android 使用 Kotlin
*** 1. Main 中的代码 Activity ***
*** 2. Style.xml ***
*** 3.模拟结果***
*** 4.我要的是***
对于透明对话框,你需要设置android:background
改变你的风格
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:background">@android:color/transparent</item>
</style>
更新
<style name="myAlertdialogstyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColor">@android:color/white</item>
</style>
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="android:background">@color/Black</item> <item name="colorAccent">@color/White</item> </style>
这里 android:Background 是 android 属性 所以它会自动反映到你的对话框
你也应该使用 Theme.AppCompat.Light.Dialog.Alert 而不是 Theme.AppCompat.Light.Dialog
我尝试将 Alertdialog 中的文本和背景颜色更改为白色文本和透明背景。但是,它没有用。
请参阅下文,让我知道我错过了什么。谢谢。
注意:Android 使用 Kotlin
*** 1. Main 中的代码 Activity ***
*** 2. Style.xml ***
*** 3.模拟结果***
*** 4.我要的是***
对于透明对话框,你需要设置android:background
改变你的风格
<style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:background">@android:color/transparent</item>
</style>
更新
<style name="myAlertdialogstyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColor">@android:color/white</item>
</style>
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <item name="android:background">@color/Black</item> <item name="colorAccent">@color/White</item> </style>
这里 android:Background 是 android 属性 所以它会自动反映到你的对话框
你也应该使用 Theme.AppCompat.Light.Dialog.Alert 而不是 Theme.AppCompat.Light.Dialog