基于背景色纺纱改变文字颜色 [英] changing spinner text color based on background color
问题描述
我有一个形象自定义的微调布局和文本的看法,但我注意到,这取决于厂家的皮肤你不能看到,因为颜色即文本。白色白色,黑色黑色。
我也注意到,没有我的其他非定制纺纱做到这一点,似乎所以我的问题是自动改变我如何能得到文字的颜色改变,以便它可以被读取?
这是一个非定制微调
ArrayAdapter<&CharSequence的GT; cAdapter;
cAdapter = ArrayAdapter.createFromResource(这一点,R.array.colors,android.R.layout.simple_spinner_item);
INT cSpinnerDD = android.R.layout.simple_spinner_dropdown_item;
cAdapter.setDropDownViewResource(cSpinnerDD);
color.setAdapter(cAdapter);
自定义飞旋我只是覆盖视图把图像与文本
下面是布局为它
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向>
< ImageView的机器人:ID =@ + ID /图标
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>
< TextView的机器人:ID =@ + ID / icon_txt
机器人:paddingLeft =25dp
机器人:TEXTSIZE =18sp
机器人:layout_marginTop =5DP
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>
使用当前主题的默认文本颜色(存储在资源ID android.R.attr.textColorPrimary
)
< TextView的机器人:ID =@ + ID / icon_txt
机器人:文字颜色=机器人:ATTR / textColorPrimary
... />
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>
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"
... />
这篇关于基于背景色纺纱改变文字颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!