1

I want to change the spinner item layout. The layout will have two TextViews. One with small size text, and the other with medium size text. The layout below is what I am using:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:minHeight="40dp"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/test1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:paddingLeft="5dp"
        android:gravity="center_vertical"
        android:text="foo" />

    <TextView
        android:id="@+id/test2"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:paddingLeft="5dp"
        android:gravity="center_vertical"
        android:text="bar" />

</LinearLayout>

This works great on my A500 tab with Ice Cream Sandwich installed. The spinner has a black background and the text has white text. However, if I use the exact same layout on a HTC Desire HD running 2.3.3, then the spinner background have changed to white. It is impossible to see the text, since this is also white.

Instead I could use textAppearance{Small,Medium}Inverse but then the situation will just be reversed. The text will be visible on HTC Desire but not on A500.

The question changing spinner text color based on background color seems to have found a solution, but as far as I can tell, textColorPrimary is included in textAppearance{Small,Medium}.

I would like to use the same layout no matter what device or android version for maintainability reasons. What should I do?

Also, it would be great if I could use the exact same layout for ListView items, again for maintainability reasons.

4

0 回答 0