我正在尝试使用多个选项更改ListView的文本颜色。我发现了很多关于它的问题,但大多数答案都建议创建一个TextView布局并将其作为解决方案分配给适配器。当我这样做时,复选框消失。
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, countries);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setAdapter(adapter);
main_activity.xml
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:scrollbarThumbVertical="@drawable/scroll"
/>
答案 0 :(得分:0)
您可以覆盖arrayAdapter中的getView方法,并像这样设置文本颜色。
ArrayAdapter<String> list = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, countries) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = converteView;
if(v = null)
v = LayoutInflater.from(YourActivity.this).inflate(android.R.layout.simple_list_item_multiple_choice, null);
TextView tv = (TextView) v.findViewById(android.R.id.text1);
tv.setTextColor("Your_color");
return v;
}
};
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setAdapter(adapter);
答案 1 :(得分:0)
我发布此帖给其他有同样问题的人。我刚刚修改了Yaw Asare的答案,但它确实有效:
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, countries){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView mytextview=(TextView)view;
mytextview.setTextColor(Color.BLUE);
mytextview.setTextSize(14);
// Other code you may want to add
return view;
}
};