changing spinner text color based on background color

你离开我真会死。 提交于 2019-12-12 03:12:47

问题


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>

回答1:


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"
    ... />



回答2:


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)



来源:https://stackoverflow.com/questions/8671413/changing-spinner-text-color-based-on-background-color

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!