我有一个 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/