我从文件填充ListView
。 ListvVew
包含复选框。现在我想更改单个项目的文字的颜色和字体在复选框上点击。相反,我只能突出显示单个项目行(蓝色)。我错过了什么?更改列表视图中选中项目的文本颜色
main.xml中
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F3E2A9">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="390dp"
android:id="@+id/linearLayoutlist"
android:orientation="vertical"
>
<ListView
android:id="@android:id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:choiceMode="multipleChoice"
android:drawSelectorOnTop="false"
android:listSelector="@drawable/listviewcolor"
>
</ListView>
</LinearLayout>
</RelativeLayout>
listviewcolor.xml
<!-- Selected -->
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@color/red" />
<!-- Pressed -->
<item
android:state_pressed="true"
android:drawable="@color/blue" />
<!-- Default -->
<item android:drawable="@color/lightyellow" />
color.xml
<color name="blue">#ff3a8dcb</color>
<color name="red">#FF0000</color>
<color name="lightyellow">#F3E2A9</color>
main_activity
List arrlist=new ArrayList();
ArrayAdapter<String> adapter2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = getListView();
listView.setChoiceMode(listView.CHOICE_MODE_MULTIPLE);
listView.setTextFilterEnabled(true);
adapter2 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, android.R.id.text1, arrlist); //arrlist is an ArrayList
//whose value is taken from a file
listView.setAdapter(adapter2);
listView.setOnTouchListener(touchListener);
listView.setOnScrollListener(touchListener.makeScrollListener());
}
你的代码在哪里? –