我想根据默认,聚焦和按下状态更改背景relativelayout:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:background="@drawable/clickable_layout_items_right_menu"
>
<TextView
android:id="@+id/txt_view_notification_right_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_notifications_right_menu"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="2dp"
android:textSize="@dimen/dim_right_menu_items"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/left_arrow"
android:layout_alignParentLeft="true"
/>
</RelativeLayout>
我的clickable_layout_items_right_menu选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:state_enabled="false"
android:drawable="@color/color_default_right_menu" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@color/color_focused_right_menu" /> <!-- focused -->
<item android:drawable="@color/color_default_right_menu" /> <!-- default -->
</selector>
颜色
<color name="color_default_right_menu">#33b5e5</color>
<color name="color_focused_right_menu">#45f209</color>
<color name="color_pressed_right_menu">#ffffff</color>
但我有问题,只有默认状态才能正常工作!
答案 0 :(得分:2)
删除android:state_enabled="false"
并将已按下的drawable替换为android:drawable="@color/color_pressed_right_menu"
。