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

时间:2014-11-19 18:27:23

标签: android android-listview background background-color listviewitem

我有一个ListView。我想为listView项设置Border,所以我使用' 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 =&#34; @ drawable / shape_panel_drawable&#34; - 当我触摸/按下列表项时,我没有看到所选的背景颜色在项目上。如果我删除&#39; background&#39;

,我会看到它

任何人都有任何想法?如果我使用背景可绘制的话,我是否会错过任何可以看到所选背景颜色的内容 - &#39; shape_panel_drawable&#39;?

谢谢!

1 个答案:

答案 0 :(得分:1)

ListView上设置此功能可能有所帮助:

android:drawSelectorOnTop="true"