Skip to content Skip to sidebar Skip to footer

Android Soft Keyboard Float Only Specific Layout

I have a layout, code below

Solution 1:

as you can say this is not work

android:windowSoftInputMode="adjustPan|adjustResize"

just change it this

android:windowSoftInputMode="stateHidden"

and one more thing in your below layout

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--some stuff here-->

<LinearLayout
    android:id="@+id/layout1"
    android:layout_alignParentBottom="true"
    android:layout_above="@+id/layout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        />
    <ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:scaleType="fitStart"
        android:layout_marginLeft="5dp"
        style="@style/Base.Widget.AppCompat.Button.Borderless"
        android:src="@drawable/ic_menu_send"/>
</LinearLayout>

<LinearLayout
    android:id="@+id/layout2"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@color/colorPrimary">
    <!--some stuff here-->
</LinearLayout>
</RelativeLayout>

Keep in Mind :

When you have applied this property android:layout_above="@+id/layout2" to layout1 of your LinearLayout then remove this property android:layout_alignParentBottom="true" you don't require it.

So Now that look like this

 <LinearLayout
        android:id="@+id/layout1"
        android:layout_above="@+id/layout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

Note : I am giving background color and specific height to LinearLayout 2 for your Understandment.

Output :

Normal Screen

enter image description here

KeyBoard Open Screen.

enter image description here

ImProve :

enter image description here

see the upper Image I make Red Mark that property create the problem otherwise every thing is work fine.


Solution 2:

Please use this, and tell me if you find any difficulties

    <?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">
    <!--some stuff here-->
    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/layout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/layout2"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal">

            <EditText
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="5" />

            <ImageButton
                style="@style/Base.Widget.AppCompat.Button.Borderless"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_marginLeft="5dp"
                android:scaleType="fitStart"
                android:src="@drawable/ic_menu_send" />
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/layout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">
        <!--some stuff here-->
    </LinearLayout>
</RelativeLayout>

Solution 3:

Use different themes for both the layouts.

such as: One theme refers to adjustPan for windowSoftInputMode attribute.

and another theme refers to adjustResize for windowSoftInputMode attribute.


Solution 4:

The fastest way is hide the layouts when soft keyboard is enable and show them again when the soft keyboard is disabled (layout2 on the xml)

Remove this Line as well

android:windowSoftInputMode="adjustPan|adjustResize"

it will work , this is just a simple way , I'm still searching for you


Solution 5:

put this line in your manifest file.

 android:windowSoftInputMode="stateHidden"

Post a Comment for "Android Soft Keyboard Float Only Specific Layout"