TextView的颜色在微调 [英] TextView Color in the Spinner
问题描述
我要的是微调的文字颜色应该当它显示在微调里面,因为它是在微调1和2以及微调的列表的文本颜色应该是黑色作为图片在运行时是白色的。
问题是我能够做到这一点的第2纱厂,但未能做到这一点的第3和第4微调。
如果你能看到3楼和4 Spinner包含的值,但在黑色。我不明白,如果它可用于2纺纱厂则y不是所有4.请帮助我。
这是我的code运行时改变颜色:
公共类文本//类改变微调的文本颜色
{
私人TextView的电视= NULL;
文本(查看spin_adptr)
{ 电视=(TextView中)spin_adptr.findViewById(R.id.textspin);
tv.setTextColor(Color.WHITE);
}
}
和我这是怎么调用它:
公共无效onItemSelected(适配器视图<>母公司,查看ARG1,INT位置,
长ARG3){
INT ID = parent.getId();
文本文本=新文本(spinner1); //颜色的变化(工作)
文字文本1 =新文本(spinner3); //颜色的变化(错误)
文字文本2 =新文本(spinner4); //颜色的变化(错误) 开关(ID){
案例R.id.spinner1: 字符串B = spinner1.getSelectedItem()的toString()。 如果(B!= NULL){
dbCarHelper.make_pop(二);
} 清单<串GT;磅= h.getAllLabels(); ArrayAdapter<串GT; dAdapter =新ArrayAdapter<串GT;(这一点,
R.layout.spin_adptr,磅); dAdapter.setDropDownViewResource(R.layout.spin_adptr);
spinner2.setAdapter(dAdapter); 打破; 案例R.id.spinner2:
文字文本1 =新文本(spinner2); ////颜色的变化(工作)
字符串= spinner2.getSelectedItem()的toString()。 如果(一个!= NULL){
dbCarHelper.m_pop(一);
} CarHelper C =新CarHelper(getApplicationContext()); 清单<串GT;拉布勒= c.getAllLabel(); ArrayAdapter<串GT; dAdaptr =新ArrayAdapter<串GT;(这一点,
R.layout.spin_adptr,拉布勒); dAdaptr.setDropDownViewResource(R.layout.spin_adptr); spinner3.setAdapter(dAdaptr);
打破; } }
请命名为spinner_layout一个XML文件,并写入code如下
<?XML版本=1.0编码=UTF-8&GT?;
< TextView中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / text1中
风格=机器人:ATTR / spinnerItemStyle
机器人:layout_width =FILL_PARENT
机器人:layout_height =48dp
机器人:重力=center_vertical
机器人:paddingLeft =4DP
机器人:TEXTSIZE =18sp
机器人:文字颜色=#FFFFFF
机器人:ellipsize =金字招牌
机器人:单线=真/>
请命名为spinner_dropdown另一个XML和下面写code
<?XML版本=1.0编码=UTF-8&GT?;
< TextView中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / text1中
风格=机器人:ATTR / spinnerItemStyle
机器人:layout_width =FILL_PARENT
机器人:layout_height =48dp
机器人:重力=center_vertical
机器人:paddingLeft =4DP
机器人:TEXTSIZE =18sp
机器人:文字颜色=#000000
机器人:ellipsize =金字招牌
机器人:单线=真/>
现在更新code如下
ArrayAdapter<串GT; dAdapter =新ArrayAdapter<串GT;(这一点,
R.layout.spinner_layout,磅); dAdapter.setDropDownViewResource(R.layout.spinner_dropdown);
What i want is the Text color of the spinner should be white at runtime when it is displayed inside the Spinner as it is in spinner 1 and 2 and the text color of the list of Spinner should be black as in the picture.
The problem is i am able to do it for the first 2 Spinners but fail to do it for the 3rd and the 4th Spinner.
If you can see the 3rd and 4th Spinner has values but in black. I don't understand that if its possible for 2 spinners then y not for all 4. please help me.
This is my code to change color at runtime:
public class Text // class for changing the text color of spinner
{
private TextView tv = null;
Text(View spin_adptr)
{
tv = (TextView) spin_adptr.findViewById(R.id.textspin);
tv.setTextColor(Color.WHITE);
}
}
and this is how i am calling it:
public void onItemSelected(AdapterView<?> parent, View arg1, int position,
long arg3) {
int id = parent.getId();
Text text = new Text(spinner1); //Change of color (Working)
Text text1 = new Text(spinner3); //Change of Color(ERROR)
Text text2 = new Text(spinner4); //Change of Color(ERROR)
switch (id) {
case R.id.spinner1:
String b = spinner1.getSelectedItem().toString();
if (b != null) {
dbCarHelper.make_pop(b);
}
List<String> lb = h.getAllLabels();
ArrayAdapter<String> dAdapter = new ArrayAdapter<String>(this,
R.layout.spin_adptr,lb);
dAdapter.setDropDownViewResource(R.layout.spin_adptr);
spinner2.setAdapter(dAdapter);
break;
case R.id.spinner2:
Text text1 = new Text(spinner2); //// Change of color (working)
String a = spinner2.getSelectedItem().toString();
if (a != null) {
dbCarHelper.m_pop(a);
}
CarHelper c = new CarHelper(getApplicationContext());
List<String> lable = c.getAllLabel();
ArrayAdapter<String> dAdaptr = new ArrayAdapter<String>(this,
R.layout.spin_adptr,lable);
dAdaptr.setDropDownViewResource(R.layout.spin_adptr);
spinner3.setAdapter(dAdaptr);
break;
}
}
make a xml file named as spinner_layout and write code as below
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:paddingLeft="4dp"
android:textSize="18sp"
android:textColor="#FFFFFF"
android:ellipsize="marquee"
android:singleLine="true" />
make another xml named as spinner_dropdown and write below code
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:paddingLeft="4dp"
android:textSize="18sp"
android:textColor="#000000"
android:ellipsize="marquee"
android:singleLine="true" />
now update your code as below
ArrayAdapter<String> dAdapter = new ArrayAdapter<String>(this,
R.layout.spinner_layout,lb);
dAdapter.setDropDownViewResource(R.layout.spinner_dropdown);
这篇关于TextView的颜色在微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!