我正在使用自定义的ListView选择器。
除了state_focused和state_pressed的可绘制对象比正常状态更大之外,一切都正常运作。
我使用ShapeDrawables而不是默认实现中使用的9-patch位图。它们都使用相同的填充值(见下文)。 似乎它们被某些其他值覆盖了。 可能是主题?但是找不到它。
ListView
列表元素布局摘录。
我使用ShapeDrawables而不是默认实现中使用的9-patch位图。它们都使用相同的填充值(见下文)。 似乎它们被某些其他值覆盖了。 可能是主题?但是找不到它。
ListView
<ListView
style="@style/dark_bg_style"
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:layout_centerInParent="true"
android:drawSelectorOnTop="false"
android:cacheColorHint="#00000000"
android:layoutAnimation="@anim/list_layout_in"
android:scrollbars="none"
android:divider="#00000000"
android:dividerHeight="5dp"
android:listSelector="@drawable/list_sel"
/>
list_sel.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/transparent" android:state_window_focused="false"/>
<item android:drawable="@drawable/button_bg_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/button_bg_focused" android:state_focused="true" android:state_selected="true"/>
<item android:drawable="@drawable/button_bg_focused" android:state_focused="true"/>
</selector>
列表元素布局摘录。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/menu_sel"
>
...
menu_sel.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/transparent"
android:state_focused="true"
android:state_selected="true"/>
<item android:drawable="@android:color/transparent" android:state_selected="true"/>
<item android:drawable="@android:color/transparent" android:state_pressed="true"/>
<item android:drawable="@drawable/button_bg_normal"/>
</selector>
button_bg_normal.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#44C8C8C8" />
<corners
android:radius="5sp" />
<padding
android:left="10dip"
android:top="5dip"
android:right="10dip"
android:bottom="5dip" />
</shape>
button_bg_pressed.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#77C8C8C8" />
<corners
android:radius="5sp" />
<padding
android:left="10dip"
android:top="5dip"
android:right="10dip"
android:bottom="5dip" />
</shape>
button_bg_focused.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#44C8C8C8" />
<corners
android:radius="5sp" />
<stroke
android:color="#55FFFFFF"
android:width="1dip" />
<padding
android:left="10dip"
android:top="5dip"
android:right="10dip"
android:bottom="5dip" />
</shape>