Lock button position in parental activity when keyboard is open

We use a fragment in Activity.Activity containing the submit button, and Fragment contains the input to the form.

Now, when we open the keyboard than this activity button, exit above the keyboard. How can we put this button and move only a fragment of a fragment.

enter image description here

enter image description here

We just want to insert this update button at the end.

+4
source share
3 answers

I added this code and it works for me. This code will hide the button when you open the keyboard and show it again when it is closed.

 parentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    Rect r = new Rect();
                    rootView.getWindowVisibleDisplayFrame(r);
                    int heightDiff = rootView.getRootView().getHeight() - (r.bottom - r.top);

                    if (heightDiff > 100) { // if more than 100 pixels, its 
                    //Hide Show Key board
                        view_one.setVisibility(View.GONE);
                        view_two.setVisibility(View.GONE);

                    }else{
                    //ok now we know the keyboard is down...
                        view_one.setVisibility(View.VISIBLE);
                        view_two.setVisibility(View.VISIBLE);

                    }
                }
            });
+2

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".SplashActivity">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true"/>

</RelativeLayout>
0

I don’t know if I’m right, but you are trying to put this code in your manifest inside the activity tag:

android:windowSoftInputMode="adjustPan"

and add this code to your button tag:

android:layout_alignParentBottom="true"
0
source

Source: https://habr.com/ru/post/1622502/


All Articles