Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog Theme: How to change item text color?

When I try to apply a standard theme to AlertDialog

AlertDialog.Builder builder = new AlertDialog.Builder(MyClass.this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);  builder.setTitle("Change");  String[] info= this.getResources().getStringArray(R.array.info);  ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.select_dialog_singlechoice);  arrayAdapter.addAll(info);  builder.setSingleChoiceItems(arrayAdapter, .... 

Result:

enter image description here

The note is that I have no problem with builder.setItems(...) since its text color is Black while the theme applied with builder.setSingleChoiceItems(...) has a White text color.

Any fast fix? Or any way to create a customized theme based on AlertDialog.THEME_DEVICE_DEFAULT_LIGHT ?

My customized style doesn't work as expected:

<style name="AlertDialogCustomTheme" android:parent="android:Theme.Dialog">     <item name="android:textColor">#7ABDFF</item>     <item name="android:windowIsTranslucent">true</item>     <item name="android:windowBackground">@android:color/transparent</item>       <!--THE FOLLOWING ITEMS HAVE NOT EFFECT ... !! -->      <item name="android:layout_centerHorizontal">true</item>     <item name="android:layout_centerVertical">true</item>     <item name="android:textColorAlertDialogListItem">#A844BD</item>     <item name="android:itemBackground">#7ABDFF</item> </style> 

Update

@lopez answer is a complete solution, but I find a single line fix for my problem, a custom theme to be applied to the activity in manifest:

<style name="MyTheme">     <item name="android:textColorAlertDialogListItem">@android:color/black</item> </style> 
like image 946
Mohsen Afshin Avatar asked Jun 21 '13 08:06

Mohsen Afshin


1 Answers

If anyone happens to read this, and is using the Suport library Alert Dialogs and wants to change the text color of list items then drop the android: part, like so:

<item name="textColorAlertDialogListItem">@color/your_color</item> 
like image 162
enyciaa Avatar answered Oct 12 '22 01:10

enyciaa