Android输入面板被键盘遮挡的解决办法

一、简介

在Android开发中,有一些非常不优化的体验,比如输入面板会被软键盘遮盖的问题。如下图。
输入面板
上图是被软键盘遮盖的原图
软键盘遮盖
上图是软键盘这个的效果
在这里插入图片描述
上图是解决之后的效果图

二、解决办法

像上图这种在实际使用中,会给用户造成非常不好的使用体验。因此,我们就需要解决办法。在网上基本都是通过修改AndroidManifest.xml中的activity属性来实现的。android:windowSoftInputMode=”adjustPan”或是android:windowSoftInputMode=”adjustResize”属性。但是在我的项目中,不起作用。就尝试另一种方案,最后完美解决问题。使用方法是,透明状态栏下使用fitsSystemWindows=true属性。

三、步骤

1.首先在需要解决遮盖问题的页面,最外层加上android:fitsSystemWindows="true"属性。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true">

    <!--其他代码忽略-->
</RelativeLayout>

此时运行程序,问题就解决了。但是会存在一个问题,在顶部会有白条。这显然也不是我们想要的效果。

猜你喜欢

转载自blog.csdn.net/nanjumufeng/article/details/127753551
今日推荐