Search code examples
androidandroid-softkeyboard

Hide show keyboard issue, showing colored background behind the keyboard


When focusing an input field, a colored (colorPrimary) background appears behind the keyboard (sometimes it extends up to 20-30px above the keyboard, overlaying the view). Hiding the keyboard makes the background visible for about 200-300ms after the keyboard is hidden and before it fades away. I am attaching a screen-shot too -

enter image description here

I tried setting (I am using fragment not activity)-

android:windowSoftInputMode="adjustPan"

Below is my layout -

                <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>

And here is my textstyle -

<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>

And my parent activity is -

<?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>

Solution

  • Generally when keyboard open/ hide it takes the background color as shadow, and if it's white we can't see the effect on a white screen, so I changed it to white and that's all.

    Below is my main activity and it is holding the fragment where I was getting issue, my fragment color was white but my main activity color was not white and that's why I was getting issue.

    <?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>