androidandroid-alertdialogandroid-styles

Android: set text color of radio button in alert dialog


I have a simple alert dialog with single choice items

val alertDialog = AlertDialog.Builder(this)
alertDialog.setTitle("My Title")
val array = arrayOf("aa", "bb", "cc")
alertDialog.setSingleChoiceItems(array, 0) { _, selectedItem ->
}
alertDialog.setNegativeButton("Cancel") { _, _ ->
}
alertDialog.create()
alertDialog.show()

I've added to my theme the custom style of alert dialog

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

     .........
     <item name="android:timePickerDialogTheme">@style/DefaultAlertDialogTheme</item>
     <item name="android:datePickerDialogTheme">@style/DefaultAlertDialogTheme</item>
     <item name="android:alertDialogTheme">@style/DefaultAlertDialogTheme</item>
</style>

And here's my style

<style name="DefaultAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:colorAccent">@color/greenButtonBackgroundColor</item>
    <item name="android:textColorSecondary">@color/greenButtonBackgroundColor</item>
    <!--title-->
    <item name="android:textColor">@color/toolbarTitleTextColor</item>
</style>

When I run the app I see this alert

enter image description here

Is there a way to change the color of the text near the radio button without creating the custom layout?


Solution

  • Try this

     val array = arrayOf(Html.fromHtml("<font color='#00FF00'>aa</font>"),
                    Html.fromHtml("<font color='#00FF00'>bb</font>"),
                    Html.fromHtml("<font color='#00FF00'>cc</font>"))
    

    You can see more details here