[英]Change Text color of checked item in Listview
I am populating a ListView
from a file. 我正在从文件填充ListView
。 The ListvVew
contains checkboxes. ListvVew
包含复选框。 Now I want to change the color and font of the text of individual items on checkbox click . 现在,我想更改复选框上单个项目的文本的颜色和字体 。 Instead I am only able to highlight the individual item row (to blue). 相反,我只能突出显示单个项目行(蓝色)。 What am I missing? 我想念什么?
main.xml 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 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.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());
}
You can change TextColor
and TextFont
Size programmatically on Checkbox
onCheckedChangeListener()
你可以改变TextColor
和TextFont
尺寸编程的Checkbox
onCheckedChangeListener()
tx.setTextSize(TypedValue.COMPLEX_UNIT_SP,30);
tx.setTextColor(Color.WHITE);
Please show your list item layout where you added check box and text view and in your adapter change text colour and font dynamically on Checkbox onCheckedChangeListener() like as follows : 请显示列表项的布局,在其中添加复选框和文本视图,并在适配器中在Checkbox onCheckedChangeListener()上动态更改文本颜色和字体,如下所示:
final Typeface tvFont = Typeface.createFromAsset(assetManager, "OPTIMA.TTF");
tv.setTypeface(tvFont);
tv.setTextColor(Color.BLACK);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.