내 안드로이드 응용 프로그램에서 내 버튼을 녹색이고 둥근 사각형으로 만들고 누군가가 버튼을 누르면 회색으로 변해야합니다. 그래서 셀렉터로 XML 파일을 만들었고 둥근 사각형을 만들었지 만, 문제는 응용 프로그램을 시작할 때 색상이 기본적으로 투명하지 않은 녹색이라는 것입니다. 또한 버튼을 누르면 직사각형 모양을 나타내므로 shapere도 작동하지 않는다고 생각합니다.모양 및 선택기가 작동하지 않습니다.
<color name="colorPrimary">#669900</color>
내 custom_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<item android:state_focused="true" android:state_pressed="false" android:color="@color/colorPrimary" android:drawable="@color/colorPrimary">
<shape
android:shape="rectangle" android:padding="10dp">
<solid android:color="@color/colorPrimary"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
</item>
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/gradient" >
<shape
android:shape="rectangle" android:padding="10dp">
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
</item>
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/gradient" >
<shape
android:shape="rectangle" android:padding="10dp">
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
</item>
</selector>
이 또한 내가 그라데이션에 대한 XML 파일을 만든 내가 만든 한
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="90"
android:startColor="#880f0f10"
android:centerColor="#880d0d0f"
android:endColor="#885d5d5e"/>
</shape>
</item>
</layer-list>