Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to push button above soft keyboard

I've got a "save" button which I want to push up together with the soft keyboard. So when the user clicks an EditText in my layout, then the button has to stay above the keyboard. Now the button becomes hidden underneath the keyboard. How do you do this?

Thanks in advance!

like image 433
Xander Avatar asked Mar 10 '13 15:03

Xander


People also ask

What is soft keyboard in Android?

The soft keyboard (also called the onscreen keyboard) is the main input method on Android devices, and almost every Android developer needs to work with this component at some point.


2 Answers

You need to set your keyboard's input mode to adjustResize. You can do this adding the following line to your activity's attributes in the manifest:

    android:windowSoftInputMode="adjustResize" 

Here's an example of the attribute added in the activity:

<activity       android:name=".activity.MyActivity"      android:windowSoftInputMode="adjustResize"> </activity> 
like image 64
Intathep Avatar answered Oct 10 '22 06:10

Intathep


Along with Inthathep's answer, you have to add an attribute in the parent viewgroup

android:fitsSystemWindows="true" 

to work it as desired. i.e, in manifest file , for the activity add

android:windowSoftInputMode="adjustResize" 

and eg.

<LinearLayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:padding="10dp"     android:fitsSystemWindows="true" <!-- add this -->     android:orientation="vertical"     >     <EditText         android:id="@+id/et_assetview_comment"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:minHeight="80dp"         android:background="@color/white"         android:hint="Enter comments"         />     <Button         android:id="@+id/btn_assetview_postcomment"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="POST"         /> </LinearLayout> 
like image 32
oneavi Avatar answered Oct 10 '22 07:10

oneavi