요점 답변 상세
에서 색상 리소스 만들기
res / values / colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="yellow" type="color">#F7B500</item>
<item name="yellow_dark" type="color">#AC7E00</item>
<integer-array name="androidcolors">
<item>@color/yellow</item>
<item>@color/yellow_dark</item>
</integer-array>
</resources>
드로어 블 만들기
res / drawable / bg_yellow_round.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/yellow" />
<stroke
android:width="2dp"
android:color="@color/yellow" />
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
</shape>
다른 드로어 블을 만들고 같은 위치에서 전환하고 이름을 지정합니다.
res / drawable / bg_yellow_dark_round.xml
<solid android:color="@color/yellow_dark" />
<stroke
android:width="2dp"
android:color="@color/yellow_dark" />
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
이제 색상 상태 목록 을
res / color / btn_selector_yellow.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="@android:integer/config_shortAnimTime">
<item android:drawable="@color/yellow" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/bg_yellow_dark_round" android:state_pressed="true"/>
<item android:drawable="@drawable/bg_yellow_round"/>
</selector>
이제 다음과 같이 버튼에 설정하십시오.
<Button
android:id="@+id/button1"
android:layout_width="248dp"
android:layout_height="44dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dp"
android:background="@color/btn_selector_yellow"
android:text="AZ_ is so cool" />
지금 이것은 전환을 할 것입니다 에서
...에
.