我有一个ListView
我已经实现了卡片 UI 类型的外观。如果 中的某个项目处于ListView
“选中”或“按下”状态,则该项目周围有一个白色边框。我希望整个视图都具有蓝色,但不知道如何实现:
ListView 项目布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="@+id/itemLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:background="@drawable/bg_cards_ui"
>
<TextView
android:id="@+id/title"
android:layout_alignParentTop="true"
android:paddingBottom="4dip"
/>
<TextView
android:id="@+id/summary"
android:paddingBottom="4dip"
android:layout_below="@id/text"
/>
<TextView
android:id="@+id/siteName"
android:layout_below="@id/summary"
/>
<TextView
android:id="@+id/date"
android:layout_below="@id/summary"
/>
</RelativeLayout>
</FrameLayout>
bg_card_ui.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" android:dither="true">
<corners android:radius="2dp"/>
<solid android:color="#ccc" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle" android:dither="true">
<corners android:radius="2dp" />
<solid android:color="@android:color/white" />
<padding
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp"
/>
</shape>
</item>
<item>
<selector>
<item android:state_pressed="true" android:drawable="@color/my_blue_color" />
<item android:state_selected="true" android:state_pressed="false" android:drawable="@color/my_blue_color" />
<item android:state_activated="true" android:state_selected="false" android:state_pressed="false" android:drawable="@color/my_blue_color" />
<item android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
</selector>
</item>
</layer-list>