android - 设置背景可绘制时,ListView 项目不显示按下的背景颜色

标签 android android-listview background background-color listviewitem

我有一个 ListView。我想为 listView 项目设置边框,所以我使用“shape”xml。

shape_panel_drawable.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#ffffff" />

    <padding
        android:bottom="8dp"
        android:left="8dp"
        android:right="8dp"
        android:top="8dp" />

    <stroke
        android:width="1dp"
        android:color="#dadada" />

    <corners android:radius="8dp" />

</shape>

list_view_item.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:background="@drawable/shape_panel_drawable" >
</RelativeLayout>

我的问题是

如果我使用 android:background="@drawable/shape_panel_drawable" - 当我触摸/按下列表项时,我没有在该项目上看到选定的背景颜色。如果我删除“背景”,我会看到它。

有人有什么想法吗?如果我使用 background drawable - 'shape_panel_drawable',我是否错过了任何东西以便能够看到选定的背景颜色?

谢谢!

最佳答案

在您的 ListView 上设置此项可能会有所帮助:

android:drawSelectorOnTop="true"

关于android - 设置背景可绘制时,ListView 项目不显示按下的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27024217/

相关文章:

android - ListView with ViewHolder,TextViews改变内容

c# - .Net 控制台应用程序在后台运行

html - 移动设备上的背景大小

java - 如何使包名带有下划线?

java - 如何使Android应用程序的图标背景透明?

Android解码xml文件中的html

java - Android - 无法从 ListView 调用 setOnItemClickListener

android - 如何将约束布局包含到另一个约束布局并在每个约束布局之间设置约束

java - 从左向右滑动从 ListView 中删除项目

css - 在 DIV 上处理悬停背景更改