My footer comes up when keyboard appears

1.5k Views Asked by At

I have made a simple footer with some buttons and it shows up quite well but I just have 1 problem that it should not come up when the keyboard is visible. It should remain down and keyboard must cover it.

Here is my layout file-

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView2"
    android:layout_above="@id/footerView">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Name"
                android:id="@+id/textView40"
                android:layout_weight="2"
                android:paddingLeft="30dp"
                android:textAlignment="gravity"
                android:layout_gravity="center_vertical" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:ems="10"
                android:id="@+id/ETNameSU"
                android:hint="Daksh Agrawal"
                android:layout_weight="1"
                android:layout_marginRight="30dp" />

    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/footerView"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/view_books"
        android:layout_weight="1" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:layout_weight="1"
        android:src="@drawable/my_profile" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView3"
        android:layout_weight="1"
        android:src="@drawable/post_book" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView4"
        android:layout_weight="1"
        android:src="@drawable/chat" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView5"
        android:layout_weight="1"
        android:src="@drawable/top_donors" />
</LinearLayout>

3

There are 3 best solutions below

0
On BEST ANSWER

Add this in your manifest activity

    android:windowSoftInputMode="hidden"
1
On

Remove android:layout_above="@id/footerView"

0
On

cross your fingers lets customize it-(Tested and working for me very well!)

In your OnCreate initialize your rootView(parent view in your XML) and your footerView

call this method from your OnCreate- once the keyboard is up footerView visibility changes

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

                if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                    //ok now we know the keyboard is up...
                    footer.setVisibility(View.INVISIBLE);


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


                }
            }
        });
    }

Hope you like it