简体   繁体   中英

changing spinner text color based on background color

I have a custom spinner layout with an image and a text view but I noticed that depending on the manufacturers skin you cant see the text because of the color ie. white on white, black on black.

I also noticed that none of my other non-custom spinners do this and seems to change automatically so my question is how can I get the text color to change so that it can be read?

this is a non-custom spinner

ArrayAdapter<CharSequence> cAdapter;
    cAdapter = ArrayAdapter.createFromResource(this, R.array.colors,android.R.layout.simple_spinner_item);
    int cSpinnerDD = android.R.layout.simple_spinner_dropdown_item;
    cAdapter.setDropDownViewResource(cSpinnerDD);
    color.setAdapter(cAdapter);

the custom spinner I just override the view to put the images in with text

here is the layout for it

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<TextView android:id="@+id/icon_txt"
    android:paddingLeft="25dp"
    android:textSize="18sp"
    android:layout_marginTop="5dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>  
</LinearLayout>

I think changing your theme changes the appearance of the listview.

I was also stucked at this point but what i did was that i made a new android app project and selected blank activity (in place of empty activity) and it worked (i know that's not a good solution but it solved my issue)

Use the default text color of the current theme (stored in the resource ID android.R.attr.textColorPrimary ) :

<TextView android:id="@+id/icon_txt"
    android:textColor="?android:attr/textColorPrimary"
    ... />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM