I want to slide my form views up when the soft keyboard is appeared. I found out that is not as easy as I thought, I've tried to change the activity's windowSoftInputMode
to adjustPan
and it do nothing, then I tried to change it to adjustResize
and it just resized my button's height.
Example of my desired result:
And when the user clicks on one of the Edit Text views I want those views to slide up:
Edit : Here is my 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"
tools:context="com.example.invity.Login"
android:background="#5dc8fc"
android:id="@+id/rlLogin">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5dc8fc"
style="@style/AppBaseThemeNoTitle" >
<ImageView
android:id="@+id/imgBG1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:scaleType="matrix"
android:src="@drawable/BG1" />
<ImageView
android:id="@+id/imgBG2"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_alignParentBottom="true"
android:scaleType="centerCrop"
android:src="@drawable/BG2" />
</RelativeLayout>
<ImageView
android:id="@+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="190dp"
android:src="@drawable/logo_white"
android:fitsSystemWindows="true" />
<EditText
android:id="@+id/txtEmail"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:hint="@string/app_login_Email_Hint"
android:layout_below="@+id/imgLogo"
android:layout_marginTop="16dp"
android:layout_marginBottom="5dp"
android:paddingLeft="3dp"
android:ems="15"
android:inputType="textEmailAddress"
android:background="@drawable/edittext_style"
android:gravity="center"
android:singleLine="true"
android:textDirection="ltr"
android:textColor="#58c9f3"
android:fitsSystemWindows="true">
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtPassword"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:hint="@string/app_login_Password_Hint"
android:layout_below="@+id/txtEmail"
android:layout_marginBottom="5dp"
android:paddingLeft="3dp"
android:ems="15"
android:inputType="textPassword"
android:background="@drawable/edittext_style"
android:gravity="center"
android:singleLine="true"
android:textDirection="ltr"
android:textColor="#58c9f3"
android:fitsSystemWindows="true"/>
<Button
android:id="@+id/btnConnect"
android:layout_width="350dp"
android:layout_height="55dp"
android:layout_centerHorizontal="true"
android:layout_alignLeft="@+id/txtPassword"
android:layout_alignRight="@+id/txtPassword"
android:layout_below="@+id/txtPassword"
android:text="@string/app_login_btn"
android:onClick="btnLoginClick"
android:background="@drawable/button_style"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:fitsSystemWindows="true"/>
</RelativeLayout>
I have 2 ImageViews that put together the background.
you need to requestFocus();
if you cant request focus u can use
(!EditText.hasFocus()){
//do nothing}
else{EditText.requestFocus();}
in some sort of update method
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.