반응형
button_state.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<corners android:radius="100dp"/>
<solid android:color="#000000"/>
</shape>
</item>
</selector>
res/drawable 안에 button_state. xml 파일을 생성한 후 위에 내용을 추가한다. shape를 변경하여 다른 모양으로도 가능하다.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@drawable/button_state"
android:text="button"
android:textColor="#ffffff"
android:gravity="center"/>
</LinearLayout>
사용하고자 하는 버튼의 background 에 @drawable/button_state 추가
반응형
'Programming > Android' 카테고리의 다른 글
안드로이드 프로그래밍 기본위젯 예제 (0) | 2021.08.16 |
---|---|
안드로이드 프로그래밍 4장 초간단계산기 (0) | 2021.08.16 |
안드로이드 프로그래밍 2장 예제 (fourbutton,edittext,radiobutton,imageview) (0) | 2021.08.16 |
안드로이드 액션바 만들기 (타이틀 가운데 정렬하기) (0) | 2021.08.14 |
안드로이드 다이얼로그 만들기 (팝업창) (0) | 2021.08.14 |