我将一个矩形放在Android屏幕上,将drawable作为RelativeLayout
的背景。以下是我如何实现它。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<RelativeLayout
android:layout_width="200dp"
android:layout_height="150dp"
android:background="@drawable/welcome_rectangle"
android:id="@+id/rectangular_orange"
android:layout_centerInParent="true"></RelativeLayout>
</RelativeLayout>
以下是welcome_rectangle
的XML drawable。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/green_welcome_rectangle" />
<item android:drawable="@drawable/orange_welcome_rectangle" />
</selector>
我想要在用户触摸时改变矩形的颜色。选择器编写时未实现这一点。如何更改选择器代码以便我可以获得我想要的内容?