Android布局底部按钮被ActionBar遮挡的解决方法
解决底部按钮被ActionBar遮挡的方案
方案1:启用系统窗口适配
在根布局ScrollView中添加android:fitsSystemWindows="true"属性,让布局自动适配ActionBar、状态栏等系统组件的占位,避免内容被遮挡:
<ScrollView 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:fillViewport="true" android:fitsSystemWindows="true">
方案2:手动添加底部内边距
给内部的ConstraintLayout设置底部内边距,使用系统提供的?attr/actionBarSize自动匹配ActionBar高度:
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="?attr/actionBarSize">
方案3:调整按钮约束与外边距
如果底部按钮是通过ConstraintLayout定位的,直接给按钮添加底部外边距,确保不被ActionBar覆盖:
<Button android:id="@+id/your_bottom_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="?attr/actionBarSize"/>
真机差异说明
模拟器和真机的ActionBar高度由系统统一控制,使用?attr/actionBarSize属性适配的话,真机不会出现差异。
内容的提问来源于stack exchange,提问作者Aethia
相关产品推荐
相关产品推荐

