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
반응형
'android' 카테고리의 다른 글
[android/안드로이드] 리스트뷰 vs 리사이클러뷰 차이점, 리사이클러뷰 개념 (0) | 2022.04.23 |
---|---|
[안드로이드,kotlin]constraintLayout 연습,제약,체인 (0) | 2022.03.19 |
[안드로이드 스튜디오,kotlin] ImageView 둥글게 만들기 (0) | 2022.03.16 |
안드로이드 공부 입문용 책 추천 : '깡샘의 안드로이드 앱 프로그래밍 with 코틀린' (0) | 2022.02.12 |
안드로이드(android) 앱개발의 특징 - 컴포넌트, 리소스 (0) | 2022.02.12 |
댓글