본문 바로가기

[ 안드로이드 ] BottomSheetDialog 테두리 둥글게 설정하기

@dongx._.22023. 4. 4. 02:58

 

 

 

사진과 같은 BottomSheetDialog를 구현해보고자 한다.

백그라운드에 대한 drawable을 만들어서 최상위 뷰의 background로 지정하면 되지 않을까 생각했었는데 적용되지 않았다.

 

background를 지정해주어야 하는 건 맞지만 themes.xml에서 설정해주어야한다. themes.xml에서 설정하는 글 들이 많이 있지만, 따라해도 안되는 경우가 많았다. 

 

같은 경우라면 아래의 코드를 시도해보면 좋을 듯하다.

 

바텀 시트 백그라운드 생성

background_bottom_sheet.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/white"/>
    <corners
        android:topRightRadius="30dp"
        android:topLeftRadius="30dp"/>
</shape>

원하는 모양으로 배경을 생성해준다.

 

Themes.xml 설정

themes.xml에 다음과 같은 코드를 추가해준다.

 

    <resources>
    
    	/.../
    	<style name="AppBottomSheetDialogTheme"
        	parent="Theme.Design.Light.BottomSheetDialog">
        	<item name="bottomSheetStyle">@style/AppModalStyle</item>	
    	</style>

    	<style name="AppModalStyle"
        	parent="Widget.Design.BottomSheet.Modal">
        	<item name="android:background">@drawable/background_bottom_sheet</item>
    	</style>
    
    </resources>

 

그 후, 기본적으로 선언되어 있던 <style name="Theme.앱이름" parent="~~~"></style> 태그 사이에 아래 코드를 추가한다.

 

    <style name="Theme.Smiley" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
		
        /*...*/
        <item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
    </style>

 

 

이렇게만 해주면 간단하게 테두리가 변경된 것을 볼 수 있다.

dongx._.2
@dongx._.2 :: DongZip

공감하셨다면 ❤️ 구독도 환영합니다! 🤗

목차