当前位置: 移动技术网 > 移动技术>移动开发>Android > android沉浸式状态栏下,键盘遮挡输入框问题

android沉浸式状态栏下,键盘遮挡输入框问题

2020年07月23日  | 移动技术网移动技术  | 我要评论

问题:

1、键盘遮挡输入框;
2、全屏或沉浸式模式下,键盘导致标题栏上移;

1、布局文件:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/cl_e0"
        android:orientation="vertical">

        <!--标题栏-->
        <com.kedacom.statusbar.widget.StatusBarHeightView
            android:id="@+id/statusbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/icon_header_bg"
            android:gravity="center"
            android:orientation="vertical"
            app:use_type="use_padding_top">
            <include
                android:id="@+id/inclue"
                layout="@layout/common_title_layout" />
        </com.kedacom.statusbar.widget.StatusBarHeightView>

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
                <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="400dp"
                    android:background="@color/cl_333"
                    android:padding="14dp">
                </android.support.constraint.ConstraintLayout>
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:layout_marginTop="10dp"
                    android:background="@color/white"
                    android:padding="14dp">
                    <EditText
                        android:id="@+id/et_contact"
                        android:layout_width="260dp"
                        android:layout_height="38dp"
                        android:layout_alignParentBottom="true"
                        android:layout_marginTop="10dp"
                        android:gravity="center_vertical"
                        android:inputType="number"
                        android:maxLength="11"
                        android:paddingStart="11dp"
                        android:textColor="@color/cl_333"
                        android:textColorHint="@color/cl_999"
                        android:textSize="16sp" />
                </RelativeLayout>
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
    </LinearLayout>

2、修复遮挡问题:

在activity的onCreate方法中调用:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN |
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                
//解决键盘档住输入框
SoftHideKeyBoardUtil.assistActivity(this);

注意事项:
1、布局文件中使用ScrollView嵌套需要滚动的布局(标题栏以下);
2、需要设置当前页面输入法模式:SOFT_INPUT_ADJUST_RESIZE(必须);注意不用受BaseActivity中的配置干扰;

特别说明(个人需求):
主页面使用了FragmentViewPagerTabLayout(内部是ViewPager),SoftHideKeyBoardUtil方法会导致键盘顶起底部导航栏,所以没有在BaseActivity中调用该方法。

本文地址:https://blog.csdn.net/zhijiandedaima/article/details/107494398

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网