Android 自定义行列表形状替代选择器状态颜色
在列表视图中,我创建了一个自定义形状来制作圆角。当我在其中添加选择器代码时,statepressed并没有达到我预期的效果。实际上,state pressed颜色显示在自定义行列表之外。i、 e它显示每个角末端的颜色。我应该如何解决这个问题 这是我的Android 自定义行列表形状替代选择器状态颜色,android,Android,在列表视图中,我创建了一个自定义形状来制作圆角。当我在其中添加选择器代码时,statepressed并没有达到我预期的效果。实际上,state pressed颜色显示在自定义行列表之外。i、 e它显示每个角末端的颜色。我应该如何解决这个问题 这是我的feed\u列表布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
feed\u列表
布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ListView
android:id="@+id/listView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:dividerHeight="10dp"
android:listSelector="@drawable/list_selector" >
</ListView>
</LinearLayout>
列表\u选择器
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- pressed state. -->
<item android:state_pressed="true"
android:drawable="@drawable/bg_yellow_dark_round"/>
</selector>
customshape
(用于圆角)
如果我删除
list\u项
中的android:background=“@drawable/customshape”
,它会工作。但是,我需要它的圆角。为什么您的列表选择器在列表视图中而不是列表项中,如果我理解您的意思,您不在列表视图中,所有的角都是圆角。
在listview中,您单击的每个智利都会有一个选择器,对吗?
如果是这样的话,您需要将customshape放在listview上,并将列表选择器放在listItem上。它只会使整个列表视图的圆角变圆,而不是每个列表项。但是,选择器是有效的。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- pressed state. -->
<item android:state_pressed="true"
android:drawable="@drawable/bg_yellow_dark_round"/>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#AC7E00" />
<stroke
android:width="2dp"
android:color="#AC7E00" />
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<stroke android:width="1dp" android:color="#006699" />
<solid android:color="#fff"/>
</shape>