0

我正在使用带有选择器资源 xml 的相对布局来突出显示点击时的相对布局。但它不会突出显示点击时的相对布局。下面我放了相应的选择器 xml、布局 xml 和可绘制对象。

布局代码片段:

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="2"
                android:id="@+id/rlShare"
                android:background="@drawable/icon_selector"
                android:clickable="true">

                <ImageView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_centerInParent="true"
                    android:contentDescription="@string/cd_new_exam"
                    android:scaleType="fitXY"
                    android:src="@drawable/share_icon" />
            </RelativeLayout>

选择器 xml 文件:

<!-- Selected -->
<item android:drawable="@drawable/icon_selected" android:state_focused="true" android:state_selected="false"/>

<!-- Pressed -->
<item android:drawable="@drawable/icon_selected" android:state_focused="false" android:state_selected="true"/>

请在这件事上给予我帮助,

先感谢您。

4

2 回答 2

2

使用此代码并从可绘制的图像中获取不同的图像

 <!-- Selected -->
<item android:drawable="@drawable/icon_selected" android:state_focused="true"         android:state_selected="true"/>

<!-- Pressed -->
<item android:drawable="@drawable/icon_pressed" android:state_focused="false" android:state_selected="true"/>

<!-- When not selected -->
<item android:drawable="@drawable/icon_default"/>
于 2014-04-18T10:41:17.990 回答
1

将此用于您的选择器:

<!-- Selected -->
<item android:drawable="@drawable/icon_selected" android:state_selected="true"/>

<!-- Pressed -->
<item android:drawable="@drawable/icon_pressed" android:state_pressed="true"/>

<!-- Default -->
<item android:drawable="@drawable/icon_default" />

请注意,在您的原始选择器中,您在两种状态下都有相同的可绘制对象。

于 2014-04-18T10:37:16.463 回答