I have seen several posts (which for some reason I cannot reply to)
that complain that there list item text is invisible when inside an
AlertDialog unless they select it.  I ran into this problem and wanted
to post my solution.

If you use AlertDialog.Builder.setItems with a simple string array,
then the Builder will create a ListView for you using
R.layout.select_dialog_item resource.  This creates working dialogs
with visible text.  The problem is when you try to use your own layout
resource (perhaps to get a two line list item layout) with your own
adapter with AlertDialog.Builder.setAdatper.  You might try to use
android.R.layout.simple_list_item_2 like I did.  This causes the
invisible text problem.

The actual problem is simply a text color issue.
android.R.layout.simple_list_item_2 uses white for the text color
which is the same color as the background of an AlertDialog, causing a
white on white situation making the text invisible.  The
R.layout.select_dialog_item layout resource used by
AlertDialog.Builder by default when using setItems specifies a text
color of android:textColor="@android:color/
primary_text_light_disable_only" which usually maps to black making
the text visible.

Therefore, to fix this problem, you need to get your text color to be
what AlertDialog would normally choose by default.  What I did was to
copy the android.R.layout.simple_list_item_2 source code xml file to
my own project so that I could edit it.  I added the setting of the
textColor with:

android:textColor="?android:attr/textColorPrimaryInverseDisableOnly"

I first tried using @android:color/primary_text_light_disable_only,
but that would not compile because it is not public to app
developers.  I scanne the android source and discovered that ?
android:attr/textColorPrimaryInverseDisableOnly maps to the exact same
thing as @android:color/primary_text_light_disable_only, so it works
great!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to