我試圖做這樣的事情是什麼WordPress的Android應用是做: https://play.google.com/store/apps/details?id=org.wordpress.android的Android留在選中的列表項邊框列表視圖
我在抽屜式導航的列表視圖。當通過使用選擇器資源選擇項目時,我設法改變背景。如何在所選項目的左側製作一個小的彩色矩形?像WordPress的應用程序。
編輯:
我的列表項佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/drawer_background_selector"
android:orientation="horizontal" >
<ImageView
android:id="@+id/drawer_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp" />
<TextView
android:id="@+id/drawer_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="8dp" />
</LinearLayout>
我的選擇:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/drawer_selected" android:state_activated="true"/>
<item android:drawable="@color/drawer_selected" android:state_selected="true"/>
<item android:drawable="@color/drawer_selected" android:state_pressed="true"/>
<item android:drawable="@color/drawer"/>
</selector>
您可以發佈您選擇的XML和資源? – ChristopheCVB
嗨!我只是補充道:D –
看看那個頁面:http://developer.android.com/guide/topics/resources/drawable-resource.html和Shape資源來創建一個你想要的drawable。 – ChristopheCVB