android:windowSoftInputMode="adjustPan"
안드로이드 앱 개발을 하다 보면, 사용자가 텍스트 입력을 위해 키패드를 열 때 하단의 네비게이션 바나 특정 UI 요소들이 함께 올라오는 불편한 현상을 마주할 때가 있습니다. 특히, 이러한 문제는 하단에 고정된 네비게이션 바를 사용할 때 자주 발생합니다. 이번 포스팅에서는 이 문제를 간단히 해결하는 방법을 공유하고자 합니다.
문제 상황
아래와 같은 레이아웃을 가진 앱이 있다고 가정해봅시다. 하단에 BottomNavigationView가 고정되어 있고, 사용자가 텍스트 입력을 위해 키패드를 열 때 이 네비게이션 바가 같이 올라오는 현상이 발생합니다.
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".ui.main.MainActivity">
<FrameLayout
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/bottom_nav_background"
app:itemBackground="@android:color/transparent"
app:menu="@menu/bottom_nav_menu"
app:itemActiveIndicatorStyle="@android:color/transparent"
app:labelVisibilityMode="unlabeled"/>
</androidx.constraintlayout.widget.ConstraintLayout>
해결 방법
이 문제를 해결하기 위해서는 AndroidManifest.xml 파일에서 해당 액티비티에 android:windowSoftInputMode 속성을 추가하면 됩니다. 이 속성을 통해 키패드가 올라올 때 UI의 동작 방식을 제어할 수 있습니다.
android:windowSoftInputMode="adjustPan" 속성은 키패드가 나타날 때 전체 레이아웃을 위로 밀어 올리지 않고, 현재 포커스가 있는 뷰만 키패드 위로 스크롤하도록 합니다. 이를 통해 하단 네비게이션 바와 같은 UI 요소가 키패드와 함께 올라가는 문제를 해결할 수 있습니다.
<activity
android:name=".ui.main.MainActivity"
android:windowSoftInputMode="adjustPan">
<!-- 기타 설정 -->
</activity>
이 설정을 적용하면, 사용자가 키패드를 열 때 하단 네비게이션 바가 고정된 채로 유지되고, 입력 중인 텍스트 필드만 키패드 위로 스크롤됩니다.
반응형
'Android > Android Core' 카테고리의 다른 글
[Android/Kotlin] DiffUtil과 ListAdapter를 활용한 효율적인 RecyclerView 업데이트 (0) | 2024.07.01 |
---|---|
[Android/Kotlin] 왜 notifyDataSetChanged 대신 DiffUtil을 사용해야 하는가? (0) | 2024.06.28 |
[Android/Kotlin] 안드로이드 ConstraintLayout에서 1:1 비율로 뷰 설정하기 (1) | 2024.06.10 |
[Android/Kotlin] 안드로이드 네비게이션: NavController 찾기의 두 가지 방법 비교 (0) | 2024.05.18 |
[Android/Kotlin] BaseFragment를 ViewBinding과 DataBinding 방식으로 생성하는 방법 (0) | 2024.05.13 |