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:
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>
What works for me
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:
Personally, I use the android
Dialog
but I use a custom layout for that match the design of my application.Here is an example:
Layout:
Result in picture:
To avoid rewriting the code every time here is a utility class :
And an example of using :
I hope you have helped!