隐藏显示键盘问题,在键盘后面显示彩色背景

Hide show keyboard issue, showing colored background behind the keyboard

聚焦输入字段时,彩色 (colorPrimary) 背景会出现在键盘后面(有时它会延伸到键盘上方 20-30 像素,覆盖视图)。隐藏键盘会使背景在隐藏键盘之后和消失之前可见约 200-300 毫秒。我也附上 screen-shot -

我尝试设置(我使用的片段不是 activity)-

android:windowSoftInputMode="adjustPan"

下面是我的布局 -

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/layout_mobile_number"
                    android:layout_marginBottom="@dimen/margin_8dp"
                    app:errorText="@{viewModel.passwordError}">
                    >
                    <EditText
                        style="@style/TextInputLayoutEditText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:drawableLeft="@drawable/password"
                        android:hint="@string/password"
                        android:inputType="textPassword"
                        android:onTextChanged="@{(text, start, before, count) -> viewModel.onPasswordTextChanged()}"
                        android:text="@={viewModel.password}"
                        />

             </android.support.design.widget.TextInputLayout>

这是我的文字样式 -

<style name="TextInputLayoutEditText" parent="@android:style/Widget.EditText">
        <item name="android:drawablePadding">@dimen/drawable_icon_padding</item>
        <item name="android:paddingLeft">@dimen/drawable_icon_padding_left</item>
        <item name="android:textSize">@dimen/common_font_size</item>
        <item name="android:textColor">@color/commonFontColor</item>
        <item name="android:textColorHint">@color/commonHintColor</item>
    </style>

而我的 parent activity 是 -

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:id="@+id/ll_top_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        ..../>
.....
</android.support.v4.widget.DrawerLayout>

一般键盘打开/隐藏的时候都是把背景色作为阴影,如果是白色在白屏上是看不到效果的,所以我改成白色就可以了。

下面是我的主要 activity,它包含我遇到问题的片段,我的片段颜色是白色,但我的主要 activity 颜色不是白色,这就是我遇到问题的原因.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:id="@+id/ll_top_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        ..../>
.....
</android.support.v4.widget.DrawerLayout>