Glaucus Glaucus - 2 months ago 11
Android Question

How to add custom layouts to appear between EditText and soft keyboard?

Hard to explain with words, but you can see what I'm talking about easily in Google Hangouts. When you tap in the EditText at the bottom to enter a comment, you see some buttons between the bottom of the EditText and the soft keyboard.

Google Hangouts EditText with buttons under it

How do you do that? I made a simple layout that has an EditText and a Button below it, but when the user taps in the EditText, the Button is obscured by the soft keyboard. Here's a cleaned up sample:

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/StandardMarginSmall"
android:layout_marginBottom="@dimen/StandardMarginSmall">
<EditText
android:id="@+id/NewComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"/>
<Button
android:id="@+id/PostComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Post"
/>
</LinearLayout>


Is there a trick into forcing it to keep those buttons viewable while in edit mode?

Answer

If you set android:windowSoftInputMode="adjustResize" on your activity, when the softkeyboard is shown, it will push the content of your activity up (resizing it), instead of overlaying on top of your activity. You'll be able to show the buttons then (they'll just be at the bottom of the layout of your activity).

Comments