Android警报对话框复选框文本

时间:2019-11-11 07:15:59

标签: android android-alertdialog material-components material-components-android

enter image description here我有一个MaterialAlertDialogBu​​ilder,我将以下ContextThemeWrapper传递给它:

<style name="MyThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="Theme.AppCompat.Dialog.Alert">
    <item name="android:background">?customfrontcolour</item>
    <item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
    <item name="buttonBarNegativeButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
    <item name="colorControlNormal">?customtextcolor</item>
    <item name="colorControlActivated">?customtextcolor</item>
</style>

我不知道如何更改复选框(“贝鲁特”)旁边文本的颜色。

我尝试了将以下所有内容添加到我的MyThemeOverlay.MaterialComponents.MaterialAlertDialog:

"textColorAlertDialogListItem"
"android:textColor"
"android:textColorPrimary"

1 个答案:

答案 0 :(得分:0)

您必须使用 android:checkedTextViewStyle 属性为对话框定义自定义样式:

  <style name="dialogCheckedStyle" parent="@style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
    <item name="android:checkedTextViewStyle" ns2:ignore="NewApi">@style/myCheckedTextView</item>
  </style>

然后定义:

  <style name="myCheckedTextView" parent="@style/Widget.MaterialComponents.CheckedTextView">
    <item name="android:textColor">@color/....</item>
  </style>

然后仅显示带有以下内容的对话框:

  new MaterialAlertDialogBuilder(this,
      R.style.dialogCheckedStyle)
      .setMultiChoiceItems(....)
      //...
      .show();

enter image description here

默认颜色由该选择器定义:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:alpha="@dimen/material_emphasis_medium" android:color="?attr/colorOnSurface"/>
</selector>