Programming/Android

안드로이드 동그란 버튼만들기 예제

fishersheep 2021. 8. 8. 14:19
반응형

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 추가

 

반응형