Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move layouts up when soft keyboard is shown?

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.

How do I get the EditText above my keyboard?

The only way to focus EditText No 8 is to hide the keyboard, scroll down and click EditText No 8 . You can scroll up without hiding the keyboard. If you set android:windowSoftInputMode="adjustResize" , the top portion of the activity (Toolbar/Appbar) is maintained with EditText pushed to above the keyboard.

How do I know my Android keyboard is displayed?

Android provides no direct way to determine if the keyboard is open, so we have to get a little creative. The View class has a handy method called getWindowVisibleDisplayFrame from which we can retrieve a rectangle which contains the portion of the view visible to the user.


Yes, check out this article on the Android developers' site which describes how the framework handles the soft keyboard appearing.

The android:windowSoftInputMode attribute can be used to specify what happens on a per-activity basis: whether the layout is resized or whether it scrolls etc.


You can also use this code in onCreate() method:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

Add in AndroidManifest.xml for your activity:

android:windowSoftInputMode="adjustPan|adjustResize"

Make changes in the activity of your Manifest file like

android:windowSoftInputMode="adjustResize"

OR

Make changes in your onCreate() method in the activity class like

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

similar issue i was facing with my layout which consist scroll view inside. Whenever i try to select text in EditText,Copy/Cut/Paste action bar gets moved up with below code as such it does not resize layout

android:windowSoftInputMode="adjustPan"

By modifying it to as below

  1. AndroidManifest.xml

    android:windowSoftInputMode="stateVisible|adjustResize"

  2. style.xml file ,in activity style

    true

It worked for me.


In AndroidManifest.xml, don't forget to set:

 android:windowSoftInputMode="adjustResize"

and for RelativeLayout inside ScrollView ,set :

 android:layout_gravity="center" or android:layout_gravity="bottom" 

it will be okay


for Activity in its oncreate methode insert below line

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

and for fragments in its onCreate method

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);