Android spinner with black text on a dark backgrou

2019-06-10 00:42发布

问题:

For an Android activity with theme:

     <android:theme="@android:style/Theme.Light.NoTitleBar">

and no other explicit colour properties, on a Motorola DroidX (Android version 2.3.340.MB810.Verizon.en.US), the spinner and button backgrounds are dark with black text although the main background is white. On most other phones, spinner and buttons appear as black text on a light grey gradient background.

Am I doing something wrong, or might this be an Android or Motorola bug?

In any case, can anyone suggest a good workaround?

回答1:

Design you own customized drawable for spinner background and apply to it. For spinnerbackground.xml images you can refer the images from the SDK. recreate the images as per your design requirements

"Android-sdk\platforms\android-9\data\res\drawable-hdpi\*.png"

spinnerbackground.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/wlbtn_dropdown_normal" />
    <item
        android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/wlbtn_dropdown_disabled" />
    <item
        android:state_pressed="true"
        android:drawable="@drawable/wlbtn_dropdown_pressed" />
    <item
        android:state_focused="true" android:state_enabled="true"
        android:drawable="@drawable/wlbtn_dropdown_selected" />
    <item
        android:state_enabled="true"
        android:drawable="@drawable/wlbtn_dropdown_normal" />
    <item
        android:state_focused="true"
        android:drawable="@drawable/wlbtn_dropdown_disabled_focused" />
    <item
        android:drawable="@drawable/wlbtn_dropdown_disabled" />
</selector>

then for spinner widget apply your custom drawable:

<Spinner android:background="@drawable/spinnerbackground"
         android:id="@+id/spinnerIDr"
         android:layout_height="wrap_content" 
         android:layout_width="fill_parent">
    </Spinner>