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

标签 android android-softkeyboard

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

enter image description here

我尝试设置(我使用的是 fragment 而不是 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 ,它包含我遇到问题的 fragment ,我的 fragment 颜色是白色,但我的主要 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>

关于android - 隐藏显示键盘问题,在键盘后面显示彩色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47427231/

相关文章:

android - 我应该在我的 react-native git repo 中 checkin 这个 android 文件夹吗?

java - 动画(偶尔)滞后

android - 背景可绘制不起作用

android - 在 WebView 中显示 iso-8859-1 编码的内容

java - 如何开始为 Android 应用程序(例如使用 OpenGL)创建 3D(游戏)GUI?

android - 如何让 EditText 粘在 Android 的软键盘上

java - 在 Android 中,如何将 View 附加到软键盘?

java - 当 editText 聚焦且键盘打开时如何移动 View ?

android - 摩托罗拉仿生 - 输入类型 textPersonName 和 textCapWords 不工作

Android - 隐藏软键盘慢