如何更改微调器中选择列表的字体颜色?
问题描述:
我创建了一个微调器,用户可以从中选择一个值。我可以改变的微调本身的文字颜色一样显示在这张照片:如何更改微调器中选择列表的字体颜色?
不幸的是,当我按下微调的项目列表,被选中,被显示,但这些上有一个白色的字体颜色白色背景,我只是没有能够改变这一点:
我google了这个问题和其他人都遇到了同样的问题。没有任何修复建议为我工作。 据我了解,我必须制作某种自定义列表,但是,我无法使其工作。有什么建议么?
我的代码看起来像这样(array_spinner是一个字符串数组):
ArrayAdapter adapter = new ArrayAdapter(this, R.layout.row, array_spinner);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
而且我row.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinnerText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textColor="#000000"
android:textSize="14dp" />
答
试试这个(未经测试)。我基本上重现simple_spinner_dropdown_item.xml
而是采用了黑色文本颜色:
- 替换行
ArrayAdapter adapter = new ArrayAdapter(this, R.layout.row, array_spinner);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
与
ArrayAdapter adapter = new ArrayAdapter(this, R.layout.row, array_spinner);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
- 添加此文件中
res/layout
,叫spinner_dropdown_item.xml
:
<CheckedTextView
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textColor="#FF000000"
/>
答
简洁明快
private OnItemSelectedListener your_spinner _name = new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
}
public void onNothingSelected(AdapterView<?> parent) {
}
};
答
我有同样的问题。我的回答并不是最正确的答案,但对于那些使用基本应用程序主题的人来说,这是一个非常快速的解决方案。
如果您正在创建使用
createfromResource()
不要使用getApplicationContext()微调一个ArrayAdapter。代之以声明Myclass.this。我的文本现在保持与基本应用程序主题相同。希望这会帮助别人。
+0
同样的问题在这里,TY – lucasjmatias 2015-04-05 18:43:11
非常感谢!它工作得很好! 感谢您的非常有用和快速的答案:) – Casper 2011-05-11 15:43:54