Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling text on a DialogFragment

I have a simple DialogFragment which shows a bit of text (which contains a Year string) and then a SeekBar that the user can slide and change the Year string.

On Android 3 and 4 this looks right... those platforms have a light background and use black text.

enter image description here

However, on Android 2, the dialog has a dark background and is still using black text.

enter image description here

I don't want to have to configure different color schemes for different versions of Android because there has GOT to be some default values built into the Android system that I should be able to use to style my TextView so that it uses the appropriate text color.

Here is my TextView that displays the year string:

<TextView
    android:id="@+id/textViewYear"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="10dp"
    android:text="1976"
    android:textAppearance="?android:attr/textAppearanceLarge" />

What settings can I apply to my TextView so that it will always be appropriately colored by the system?

Note, I can't just use an Inverse style, because on Android 3 and 4 it is working properly. If I use an Inverse text appearance then it works on Android 2, but fails on 3 and 4.

like image 567
Kenny Wyland Avatar asked Nov 03 '22 01:11

Kenny Wyland


1 Answers

I found the solution on another SO post:

builder.setInverseBackgroundForced(true)

On Android 3.x and 4.x this doesn't seem to change anything, but on Android 2.x it inverts the color scheme so that the background is white so the black text shows up properly.

like image 131
Kenny Wyland Avatar answered Nov 15 '22 13:11

Kenny Wyland