我有一个对话框,其中的选项以黑色文本显示,我想将其设置为白色
@SuppressLint("CutPasteId")
private fun showPageSelectionDialog() {
val options = arrayOf("A4", "A5") // User options
val builder = AlertDialog.Builder(this, R.style.MyAlertDialogStyle)
builder.setTitle("Select PDF size")
.setItems(options) { _, which ->
val selectedPageSize = if (which == 1) PageSize.A5 else PageSize.A4
pdf(name.text.toString().trim(), selectedPageSize)
}
.setNegativeButton("Cancel") { dialog, _ ->
dialog.dismiss()
}
builder.create().show()
}
由于我在应用程序中使用了更多对话框,因此我创建了自定义样式:
<!-- DIALOGUE -->
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowBackground">@drawable/dialog_background</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:textColorSecondary">@color/blue</item>
<item name="android:textAppearance">@color/white</item>
</style>
您可以使用
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.MyAlertDialogStyle));
为您的对话框设置主题。如果您想更改按钮颜色,请使用以下样式:
<style name="MyAlertDialogStyle" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item></style>
对于积极按钮:
<style name="NegativeButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#f00</item></style>
对于否定按钮:
<style name="PositiveButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#00f</item></style>
添加
<item name="android:textColor">@color/white</item>
适合您的风格