Android ListView及其文本颜色
我有CustomListView(包含背景图像和文本视图) 选择项目时,我需要更改背景图像和字体颜色,目前我可以使用xml更改listview中选定行的背景,但无法更改文本颜色 默认情况下,当单击listview中的项目时,我的文本颜色为黑色。我需要将文本颜色更改为白色 我对我的customlistview使用以下布局Android ListView及其文本颜色,android,Android,我有CustomListView(包含背景图像和文本视图) 选择项目时,我需要更改背景图像和字体颜色,目前我可以使用xml更改listview中选定行的背景,但无法更改文本颜色 默认情况下,当单击listview中的项目时,我的文本颜色为黑色。我需要将文本颜色更改为白色 我对我的customlistview使用以下布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schem
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="29dp"
android:id="@+id/appcategoryLinearLayout"
android:background="@drawable/appcategorybg1"
android:gravity="left|center_vertical"
>
<TextView
android:gravity="left|center_vertical"
android:text="fdsfsdfsdfdsfdsfdsf"
android:paddingLeft="8dp"
android:textSize="8dp"
android:textColor="@color/black"
android:id="@+id/appCategoryNameTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
编写自己的ListAdapter和编写自定义控件的唯一方法是使用您定义的可视属性 我不确定这是否对你有帮助,但你可以做这样的事情 将TextView变量用作全局变量
TextView t ;
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
if(t != null)
{
//reset the color to black
}
LinearLayout lay = (LinearLayout)v;
t = lay.getChildAt(0);
//now set text to bold
}
};
你能发布XML布局吗?我已经写了彩色XML,我把它设置为textcolor,现在它工作得很好,而不是在XML中更改,用编程的方式做会更容易。。。在onClickListener中,您只需使用txt.setColorint更改textcolor;method@Sarabh你的想法是可行的,但问题是我无法将白色重置为黑色,当字体变为白色时,总是这样,我想在选择新行时将其他文本重置为黑色。