How can I position a layout right above the android on-screen keyboard?

20,534

Solution 1

Make sure your soft input mode is set to adjustResize, then place the layout with your toolbar at the bottom of your activity.

Example:

<LinearLayout android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <FrameLayout android:id="@+id/my_content"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="1">
        <!-- Your content here -->
    </FrameLayout>
    <LinearLayout android:id="@+id/my_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        <!-- Your toolbar items here -->
    </LinearLayout>
</LinearLayout>

Solution 2

This is for people who after setting the adjustResize still did not work, there is an article: adjustResize does not work in fullscreen

I indeed had this set to fullscreen, when setting my theme back to a nonfullscreen theme the layouts resized just as wanted.

Share:
20,534

Related videos on Youtube

Sheehan Alam
Author by

Sheehan Alam

iOS, Android and Mac Developer. i can divide by zero.

Updated on July 09, 2022

Comments

  • Sheehan Alam
    Sheehan Alam almost 2 years

    See the attached photo. Twitter does it well. They have a layout, which I will call a toolbar for lack of a better term, right above the onscreen keyboard. How can I do this with my code?

    enter image description here

    UPDATE: Here is my layout:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ffffff">
        <RelativeLayout android:id="@+id/actionbarRelativeLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/actionbar_gradient">
            <ImageButton android:id="@+id/imageButton" android:layout_width="wrap_content" android:background="@drawable/stocktwits" android:layout_height="wrap_content"></ImageButton>
            <TextView android:layout_width="wrap_content" android:id="@+id/charCountTextView" android:text="140" android:layout_alignParentRight="true" android:layout_height="wrap_content" android:textColor="#ffffff" android:textStyle="bold" android:textSize="18sp" android:gravity="center_vertical" android:layout_centerVertical="true"></TextView>
        </RelativeLayout>
        <EditText android:layout_width="match_parent" android:id="@+id/composeEditText" android:focusable="true" android:hint="Share an idea with the community" android:gravity="left|top" android:layout_height="fill_parent" android:layout_weight="1"></EditText>
        <LinearLayout android:layout_width="match_parent" android:id="@+id/border" android:background="#c4c4c4" android:baselineAligned="false" android:layout_height="1dp"></LinearLayout>
        <LinearLayout android:layout_height="wrap_content" android:id="@+id/toolbarLinearLayout" android:orientation="horizontal" android:padding="5dip" android:layout_width="fill_parent" android:background="@drawable/gray_toolbar_gradient">
            <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/shortenButton" android:background="@drawable/shortenbutton" android:layout_weight="0"></Button>
            <LinearLayout android:layout_height="match_parent" android:layout_width="wrap_content" android:id="@+id/linearLayout1" android:layout_weight="1"></LinearLayout>
            <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/twitterCheckBox" android:textColor="#000000" android:layout_weight="0" android:background="@drawable/twittergraybutton"></CheckBox>
            <Button android:layout_height="wrap_content" android:layout_weight="0" android:id="@+id/sendButton" android:layout_width="wrap_content" android:background="@drawable/sharebutton"></Button>
        </LinearLayout>
    
    </LinearLayout>
    

    And here is my Manifest where I specify the softInputMode:

    <activity android:name="ShareActivity"
                  android:theme="@android:style/Theme.NoTitleBar"
                  android:windowSoftInputMode="adjustResize">
        </activity>
    
  • Sheehan Alam
    Sheehan Alam almost 13 years
    I made my soft input mode set to adjustResize. No luck unfortunately.
  • adamp
    adamp almost 13 years
    Change the layout_height="fill_parent" on your EditText to layout_height="0dip" and let the weight handle it.
  • Sheehan Alam
    Sheehan Alam almost 13 years
    I had getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT‌​_INPUT_STATE_ALWAYS_‌​VISIBLE); in onCreate() which messed everything up. removing this line in conjunction with your recommendations have worked.
  • JCasso
    JCasso over 11 years
    +10 thanks for the tip. You have to use Theme.Holo.NoActionBar instead.
  • Alex Perevozchykov
    Alex Perevozchykov over 8 years
    I've searched quite a lot for this answer. Thank you ! This answer should be marked as correct.
  • Taranmeet Singh
    Taranmeet Singh almost 8 years
    I have spent more than 10 hours at last some consolation here.