Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 高亮显示所选listview项,并具有高亮显示效果_Android_Listview_Android Cursoradapter - Fatal编程技术网

Android 高亮显示所选listview项,并具有高亮显示效果

Android 高亮显示所选listview项,并具有高亮显示效果,android,listview,android-cursoradapter,Android,Listview,Android Cursoradapter,我有一个列表视图,它是多重选择的。每次我选择一个项目时,它都必须高亮显示。。然而,我希望它是一个高亮效果,而不是着色整行 目标: 与此相反: 主要活动布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:l

我有一个列表视图,它是多重选择的。每次我选择一个项目时,它都必须高亮显示。。然而,我希望它是一个高亮效果,而不是着色整行

目标:

与此相反:

主要活动布局

<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.peace.webelieve.Niv">

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/listView2"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_above="@+id/seekBar2" 
    android:choiceMode="multipleChoice"
    android:listSelector="@android:color/transparent"/>

<SeekBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/seekBar2"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignRight="@+id/listView2"
    android:layout_alignEnd="@+id/listView2" />

自定义列表布局

<?xml version="1.0" encoding="utf-8"?>

>

首先,您需要为您的
ListView
创建一个自定义行(您的行将包含
TextView
和…。
然后,您应该为自定义行设置背景,这样可以防止您按下时的行高亮显示。
最后,当按下TextView状态->更改TextView背景时,为
TextView
的背景添加选择器

对于您的listview

  <ListView
   ...
   android:listSelector="@android:color/transparent" // add this line for disable ListView hightlight when press
  />
还可以创建xml文件
选定的\u后台

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
 android:shape="rectangle">
 <solid android:color="#0000ff" />
</shape>


希望获得此帮助首先,您需要为自己创建一个自定义行
ListView
(您的行将包含
TextView
和…。
然后,您应该为自定义行设置背景,这样可以防止您按下时的行高亮显示。
最后,当按下TextView状态->更改TextView背景时,为
TextView
的背景添加选择器

对于您的listview

  <ListView
   ...
   android:listSelector="@android:color/transparent" // add this line for disable ListView hightlight when press
  />
还可以创建xml文件
选定的\u后台

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
 android:shape="rectangle">
 <solid android:color="#0000ff" />
</shape>


希望此帮助

非常感谢您的回复:)但整行仍然高亮显示,我的目标是只突出显示文本,就像第一幅图像一样,这可能吗?@I已更新我的答案,我已在
列表视图中添加了一行
。请你再检查一遍,然后告诉我结果仍然像上面的第二张图片在你的问题中添加你的布局,然后我会很容易检查请在你的问题中添加你的
ListView
行布局代码非常感谢你的回答:)但是整行仍然突出显示,我的目标是只突出显示文本,就像第一幅图像一样,这可能吗?@我已经更新了我的答案,我已经在
列表视图中添加了一行。请你再检查一遍,然后告诉我结果仍然像上面的第二张图片。在你的问题中添加布局,然后我会很容易检查。请在你的问题中添加
列表视图
行布局代码
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
 android:shape="rectangle">
 <solid android:color="#0000ff" />
</shape>