본문 바로가기
android

안드로이드(android) 버튼 커스텀/모서리가 둥근 버튼/버튼 그림자효과/버튼 둥글게

by 래끼 2022. 2. 17.
728x90
반응형

 

둥근 버튼 만들기

1. 버튼이 둥근 모양으로 출력될 수 있도록 버튼의 백그라운드에 설정되는 XML 파일을 만든다

[res->drawable] 디렉터리에서 오른쪽 버튼을 눌러서 [New->Drawable Resource File] 메뉴 선택

 

파일이름을 round_button으로 짓고 ok를 눌러 drawable file을 만든다.

 

2. round_button.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners
        android:bottomRightRadius="30dp"
        android:bottomLeftRadius="30dp"
        android:topLeftRadius="30dp"
        android:topRightRadius="30dp"/>

</shape>

 

shape을 rectangle로 해주고

<corners> 태그에서 bottomRightRadius, bottomLeftRadius, topLeftRadius, topRightRadius로 각 모서리를 설정해준다.

 

 

 

둥근 버튼 적용하기 , 버튼에 그림자 효과 주기

activity_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"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_margin="20dp"
        android:background="@drawable/round_button"
        android:elevation="30dp"
        android:text="button 1" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@drawable/round_button"
        android:elevation="30dp"
        android:text="button 2" />

</LinearLayout>

 

activity_main.xml 파일에서 Button을 만들고 버튼의 background를 round_button으로 설정해준다.

버튼에 그림자효과를 적용할때는 해당 <Button>태그에서 elevation으로 효과를 적용한다.

728x90
반응형

댓글