프로그래밍/안드로이드, 코틀린
안드로이드 모서리가 둥근 버튼을 만드는 아주 쉬운 방법 (Rounded Button)
toonraon
2023. 3. 1. 01:45
인터넷에 검색해보면 다들 참 어려운 방법을 쓰고 앉아있는데 사실 요즘은 참 쉬운 방법이 있습니다.
xml에서 버튼 속성에 app:cornerRadius="{숫자}dp"
만 주면 됩니다.
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="4dp"
android:text="0dp"
app:cornerRadius="0dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="4dp"
android:text="10dp"
app:cornerRadius="10dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="4dp"
android:text="20dp"
app:cornerRadius="20dp" />
</LinearLayout>
참고로 Button에만 적용되고 TextView나 다른 것들엔 적용 안 되기 때문에 어려운 방법으로 구현해야하는 게 맞습니다.
버튼만 쉽게 가능.