我正在填充文件中的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());
}
答案 0 :(得分:2)
您可以TextColor
TextFont
Checkbox
和onCheckedChangeListener()
尺寸
tx.setTextSize(TypedValue.COMPLEX_UNIT_SP,30);
tx.setTextColor(Color.WHITE);
答案 1 :(得分:1)
请显示列表项目布局,其中添加了复选框和文本视图,并在适配器中动态更改文本颜色和字体在Checkbox onCheckedChangeListener()上,如下所示:
final Typeface tvFont = Typeface.createFromAsset(assetManager, "OPTIMA.TTF");
tv.setTypeface(tvFont);
tv.setTextColor(Color.BLACK);