Android Compose中如何让BottomBar显示在软键盘上方?
解决软键盘弹出时BottomBar被覆盖的问题
当前问题:软键盘弹出时会覆盖底部的BottomBar,导致无法正常操作,希望BottomBar能被顶至键盘上方。
解决步骤:
配置Activity的软键盘适配模式
在AndroidManifest.xml中找到对应的Activity,添加或修改android:windowSoftInputMode属性为adjustResize:<activity android:name=".YourActivity" android:windowSoftInputMode="adjustResize"> </activity>该属性会让系统在软键盘弹出时重新调整布局大小,使底部的BottomBar自动上移至键盘上方。
确保BottomBar的布局属性正确
检查布局文件,保证BottomBar固定在屏幕底部:- 若使用RelativeLayout:
<com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottomBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"/> - 若使用ConstraintLayout:
<com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottomBar" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent"/>
- 若使用RelativeLayout:
适配全屏/沉浸式布局(若有使用)
如果Activity启用了全屏或沉浸式模式,需给根布局添加android:fitsSystemWindows="true",避免布局被系统栏遮挡同时保证resize生效:<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <!-- 其他布局内容 --> <com.google.android.material.bottomnavigation.BottomNavigationView .../> </androidx.constraintlayout.widget.ConstraintLayout>
内容的提问来源于stack exchange,提问作者Olaleye Paul Tobi
相关产品推荐
相关产品推荐

