Soft keyboard hides half of EditText
Asked Answered
A

6

23

I have a ListView and the last list item contains EditText:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/contentLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="30dp"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/messageEditText"
            android:layout_below="@+id/messageEditText"
            android:layout_marginRight="14dp"
            android:src="@drawable/test" />

        <EditText
            android:id="@+id/messageEditText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_toLeftOf="@+id/sendImageButton"
            android:ems="10"
            android:gravity="top"
            android:hint="@string/messageEditText"
            android:inputType="textMultiLine"
            android:minHeight="55dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp" />

        <ImageButton
            android:id="@+id/sendImageButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@id/messageEditText"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@id/messageEditText"
            android:adjustViewBounds="true"
            android:maxHeight="55dp"
            android:maxWidth="55dp"
            android:padding="12dp"
            android:scaleType="centerInside"
            android:src="@drawable/sendmessage" />

    </RelativeLayout>
</RelativeLayout>

Half of the EditText is hidden. I also can't scroll ListView. Any solution?

image

Attractant answered 21/11, 2013 at 17:43 Comment(3)
possible duplicate of Android soft keyboard covers edittext fieldPeriotic
I'm experiencing the same issue event after setting android:windowSoftInputMode="adjustResize|stateHidden" and using a scrollview. Any other suggestions?Encumber
[The property android:windowSoftInputMode="adjustResize" doesn't work with full screen activity, you have to remove activity full screen flags in order to get advantage of adjust resize. ](https://mcmap.net/q/584898/-keyboard-overlapping-issue-on-edittext-with-adjustpan-not-working)Lewie
A
33

Solution was to set an android:softInputMode attribute to adjustResize in Manifest and put layout(not list item layout) inside a ScrollView.

Attractant answered 18/12, 2013 at 17:18 Comment(0)
B
9

I Had a similar issue, then i used android:windowSoftInputMode="adjustResize|stateHidden" as mentioned here.. It works very well for me..

Benzophenone answered 18/9, 2014 at 5:33 Comment(1)
Hi @IgorGanapolsky.. stateHidden setting will hide soft keyboard when user enters new Activity (even if EditText control gains the focus). Soft keyboard will be shown only when user clicks the edit box control.Benzophenone
A
3

From my early days as a Android Developer I struggled with the virtual keyboard. I am amazed that Android is still not giving an elegant and clear solution for this.

So here is the Workaround that will put this mess behind you. it will work without the ScrollView workaround or giving away your full screen flag.

  1. Add this awesome Library to your gradle file:

compile'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:1.0.1'

  1. Make sure your activity has the following keyboard settings:

android:windowSoftInputMode="adjustResize"

  1. wrap your EditText with a vertical LinearLayout and add a View with Visibility of Gone:

    <com.ylimitapp.ylimitadmin.views.NormalFontEditText
        android:id="@+id/input_et"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textCapSentences|textMultiLine"
        android:imeOptions="actionSend"
        android:paddingStart="20dp"
        android:paddingEnd="40dp"
        android:paddingTop="10dp"
        android:maxHeight="120dp"
        android:adjustViewBounds= "true"
        android:scrollHorizontally="false"
        android:textColorHint="#7b7b7b"
        android:hint="@string/type_your_message"
        android:background="@drawable/msg_inputfield_bg"
        android:textColor="@color/black_text_color"
        android:textSize="15.33sp"
        />
    
        <View
            android:id="@+id/keyboard_view"
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:visibility="gone"
            />
    
    </LinearLayout>
    
  2. calculate the screen size so you can calculate the height of the view that pushes the EditText:

    private void storeScreenHeightForKeyboardHeightCalculations() {
                Rect r = new Rect();
                View rootview = getActivity().getWindow().getDecorView(); 
                rootview.getWindowVisibleDisplayFrame(r);
                mOriginalScreenHeight = r.height();
    
                Rect rectangle = new Rect();
                Window window = getActivity().getWindow();
                window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
                int statusBarHeight = rectangle.top;
                int contentViewTop =
                        window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
                int titleBarHeight= contentViewTop - statusBarHeight;
    
                if (titleBarHeight == 0) {
                    mOriginalScreenHeight -= (24 * Utils.getDensity(getContext()));
                }
            }
    
    1. Add a Listener for keyboard open and close event and then set the height of the View below the EditText on runtime so we will set the height properly on any device and custom keyboards. then simply make it Visible when the Keyboard is Open:
private void addkeyBoardlistener() {
           KeyboardVisibilityEvent.setEventListener(
                            getActivity(),
                            new KeyboardVisibilityEventListener() {
                                @Override
                                public void onVisibilityChanged(boolean isOpen) {
                                    if (isOpen) {
                                        Rect r = new Rect();
                                        View rootview = getActivity().getWindow().getDecorView(); // this = activity
                                        rootview.getWindowVisibleDisplayFrame(r);
                                        int keyboardHeight = (mOriginalScreenHeight - r.height());
                                        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) keyboard_view.getLayoutParams();
                                        params.height = (int) ((keyboardHeight + 5 * Utils.getDensity(getContext())));
                                        keyboard_view.setLayoutParams(params);
                                        keyboard_view.setVisibility(View.VISIBLE);
                                    } else {
                                        keyboard_view.setVisibility(View.GONE);
                                    }
                                }
                            });
                }

This is the result:

Result:

Array answered 20/11, 2016 at 7:14 Comment(0)
H
2

Disable the keyboard on window startup

this .getWindow().setSoftInputMode(WindowManager.LayoutParams. SOFT_INPUT_STATE_ALWAYS_HIDDEN );
Hyde answered 10/9, 2014 at 2:43 Comment(0)
H
1

Set an android:softInputMode attribute for your Activity element in your Manifest.

See the Manifest documentation for a full list of valid values and their effect. The ones of particular interest to you will likely be adjustPan and adjustResize.

Haviland answered 21/11, 2013 at 17:52 Comment(2)
@Tanis.7x You cannot use both - adjustPan and adjustResize.Paradis
I never said to use both- I mentioned both because either could be applicable depending on the desired end behavior. You should look at the documentation for both and choose the one that provides the behavior you want.Haviland
D
0

Add this in the manifest like so:

<activity
    android:name="your_activity_name"
    android:windowSoftInputMode="adjustResize"
    android:theme="@style/Theme.AppCompat.DayNight.NoActionBar" />

Then add paddingBottom="20dp" in your layout and editText.

Dilute answered 8/6, 2020 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.