본문 바로가기

Android App/Tip

[Android/Tip] API 29에서 BottomSheet의 peek_height가 다르게 보이는 문제 해결하기(How to make same peek_height of BottomSheet on API 29)

문제 상황

peek_height를 설정한 BottomSheet가 AVD 상에서 잘 작동하는 것을 확인했으나, 실제 기기인 갤럭시 노트10(안드로이드 Q)에서는 BottomSheet가 다 보이는, 즉 peek_height 속성의 값이 적용되지 않는 문제가 있었다. 심지어 숨겨지지도 않았다.

해결 방법

안드로이드 Q에서부터 BottomSheet 제스처와 시스템 네비게이션 제스처와의 충돌을 방지하기 위해 GestureBottomInserts가 default behavior로 설정했기 때문이라고 한다. API29에서도 BottomSheet가 동일하게 동작하기 윈한다면 이를 무시하는 속성인 "gestureInsetBottomIgnored"를 trure로 설정하면 된다. XML과 프로그래밍 코드 상에서 모두 가능하다.

아래는 Java 설정 코드 예제이다.

BottomSheetBehavior<View> behavior = BottomSheetBehavior.from(bottomSheetBehaviorView);
behavior.setGestureInsetBottomIgnored(true);

 

XML로 설정하는 방법은 아래 참고한 글에 나와있다. style.xml로 설정하는 방법인데, 나는 코드로 설정하는 것이 더 편해서 위 코드로 설정해서 해결하였다.

 

*참고한 글

 

[Bottom Sheet] Bottom Sheet peek height gives different results on API 29 · Issue #1472 · material-components/material-compone

Description: The bottom sheet's peek height appears differently on API 29. It works correctly for 28 and below but gives incorrect peek behavior on 29. Expected behavior: I set the peak height ...

github.com