2

There is a LinearLayout include a EditText at the bottom of screen in my program when I tap EditText to type some text, the keyboard is appeared and the EditText height is shrinked, so I can't see what I wrote in EditText.

before keyboard

after keyboard

I searched about this and found out that maybe it's about AndroidManifest.xml file. So I add this line to the file:

 android:windowSoftInputMode="adjustPan"

But this not work as I want after I added this code into manifest EditText is placed behind the keyboard.

after adding code to AndroidManifest file

Finally I want to know is there any way to prevent resizing views while the keyboard is show?

My Activity XML code :

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark">
    </android.support.design.widget.AppBarLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="10"

        app:layout_constraintTop_toTopOf="parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/msgView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="9"
            android:background="@drawable/sssaaa">
        </android.support.v7.widget.RecyclerView>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#80000000"
                android:weightSum="10">
                <EditText
                    android:id="@+id/txt_message"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_weight="8.8"
                    android:background="@drawable/rounded_corner"
                    android:hint="@string/hint"
                    android:inputType="text"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:textColor="#000000" />
                <Button
                    android:id="@+id/btn_send"
                    android:layout_width="0dp"
                    android:layout_height="40dp"
                    android:layout_gravity="center_horizontal|center_vertical"
                    android:layout_weight="1"
                    android:background="@drawable/circular_button"
                    android:textColor="#000000"
                    android:textSize="18sp" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

Molly
  • 1,887
  • 3
  • 17
  • 34

2 Answers2

1

Try this:

android:windowSoftInputMode="stateVisible|adjustNothing"
Dinesh Shingadiya
  • 988
  • 1
  • 8
  • 23
  • 2
    i tried this and not work.the result is that .When the program runs, without typing, the keyboard opens and the box is hidden behind it. – pooya mahmoodi May 09 '19 at 16:16
  • This will work if EditText is on the top of the screen, but will fail if edittext is on the bottom of the screen. – Narendra Singh May 06 '20 at 09:51
1

I found a workaround, since you are using the Constraint Layout, I have separated the two Linear Layout, the RecyclerView and the send message field. Since EditText will always be on the screen and the RecyclerView already contains a ScrollView they may be competing on the screen, RecyclerView does not need to occupy the entire screen.

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/linearLayout">

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="vertical"
    android:weightSum="0"

    app:layout_constraintBottom_toTopOf="@+id/linearLayout"
    app:layout_constraintTop_toTopOf="parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/msgView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="9">

    </android.support.v7.widget.RecyclerView>


</LinearLayout>

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="vertical"
    app:layout_constraintBottom_toBottomOf="parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#80000000"
        android:weightSum="10">

        <EditText
            android:id="@+id/txt_message"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginBottom="5dp"
            android:layout_weight="8.8"
            android:inputType="text"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:textColor="#000000" />

        <Button
            android:id="@+id/btn_send"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_weight="1"

            android:textColor="#000000"
            android:textSize="18sp" />

    </LinearLayout>
</LinearLayout>

enter image description here

To test I removed the lines that contained drawables, just put them back and run the code.

Notice that I change de height of the parent Linear Layout of EditText to 50dp

Daniel Beltrami
  • 756
  • 9
  • 22
  • Thanks Daniel ... I tried your code , but the problem still remains.Especially when I type Persian characters the EditView is placed completely behind the keyboard. – pooya mahmoodi May 10 '19 at 12:56
  • I think you need to remove this code `android:windowSoftInputMode="adjustPan"` from Manifest – Daniel Beltrami May 10 '19 at 13:08