我是 android 新手..所以需要一些帮助.. 我有一个带有白色背景的 xml 页面..其中有一个微调器..解析后值正在那个微调器中填充..但问题是当我点击那个微调器时文本颜色也是白色的并且它的背景微调器也是白色的..因此文本不可见..我希望微调器的所有项目都应该是黑色的..我有一些线但是通过那个只有选定的项目显示黑色...... 需要你的帮助...提前谢谢..
最佳答案
您必须已经实现了微调器的 onItemSelected。 像这样:
public class YourActivity_Name extends Activity implements
AdapterView.OnItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
spinner = (Spinner) findViewById(R.id.Spinner1);
spinner.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
更新:
那么你必须像这样在微调器中设置项目:
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
context, android.R.layout.simple_spinner_item,
array_spinner);
adapter.setDropDownViewResource(R.layout.simple_selectable_list_item);
spinner.setAdapter(adapter);
simple_selectable_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceListItem"
android:gravity="center_vertical"
android:background="?android:attr/listChoiceBackgroundIndicator"
android:paddingLeft="8dip"
android:textColor="#ff0000"
android:paddingRight="8dip"
/>
关于android - 更改解析后出现的微调项的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17161125/