Search code examples
android-fragmentsandroid-softkeyboardandroid-keypadfragmentmanager

How to put fragment on top of soft kevboard?


I have an Android fragment with a EditText. Since I would like to enter there something, I managed to display the keyboard as well, when opening this fragment.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:id="@+id/viewgroup_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/viewgroup_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <View
            android:id="@+id/view_placeholder"
            android:layout_width="match_parent"
            android:layout_height="336dp"
            android:clickable="false"
            android:src="@drawable/img_placeholder_400"
            android:layout_weight="0.64" />

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:paddingBottom="@dimen/margin_bot"
                android:paddingLeft="@dimen/margin_left"
                android:paddingRight="@dimen/margin_right"
                android:paddingTop="20dp"
                android:background="@color/dark"
                android:focusableInTouchMode="true"
                android:weightSum="1">

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

                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Enter name"
                            android:id="@+id/textView_fragment_title"
                            android:textColor="@color/white"
                            android:clickable="false" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="You can enter your name here.. "
                            android:id="@+id/textView_fragment_subtitle"
                            android:textColor="@color/blueTone" />
                    </LinearLayout>

                    <ImageButton
                        android:id="@+id/btn_close_fragment_fragment"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:scaleType="center"
                        android:src="@drawable/ic_darkblue_20"
                        android:layout_gravity="right"
                        android:layout_alignParentTop="true"
                        android:layout_alignParentRight="true"
                        android:layout_alignParentEnd="true" />
                </RelativeLayout>

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:id="@+id/editText_fragment_content"
                    android:background="@color/white"
                    android:inputType="text"
                    android:imeOptions="actionDone"
                    android:hint="Enter name here ..."
                    android:layout_marginTop="10dp">
                    <requestFocus/>
                </EditText>
            </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</LinearLayout>

But my keyboard is in front of my fragment, and thus my fragment is not visible anymore.

I would like to have my keyboard on the bottom, and on top of my soft keybaord my fragment as in this example screenshot

How can I put my fragment on top of the Android soft keyboard?


Solution

  • Following solved my issue:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        android:id="@+id/viewgroup_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:focusableInTouchMode="true"
            android:layout_alignParentBottom="true"
            android:weightSum="1">
            <MY_STUFF>
        </LinearLayout>
    </RelativeLayout>