How to automatically set whole layout top of android keyboard while EditText is selected.
By default android keypad dose not move the activity screen layout and shows just above the layout screen but this kind of functionality sometimes interrupt the user experience because while user starts typing on EditText then it will not move automatically. So by using android:windowSoftInputMode=”stateVisible|adjustPan” code inside your AndroidManifest.xml file will enable the automatically activity screen movement while user starts typing on EditText. So here is the complete step by step tutorial for Move EditText layout just above soft keyboard when it shows in android.
How to Move EditText layout just above soft keyboard when it shows in android.
Code for MainActivity.java file.
package com.moveedittext_android_examples.com; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
Code for activity_main.xml layout file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.moveedittext_android_examples.com.MainActivity" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="126dp" android:ems="10" android:hint="This is EditText" android:gravity="center" > </EditText> </RelativeLayout>
Code for AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.moveedittext_android_examples.com"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateVisible|adjustPan"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Screenshot: