0

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:

Soft keyboard is hidden

And when the user clicks on one of the Edit Text views I want those views to slide up:

Soft keyboard is visible

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.

Ori Seri
  • 789
  • 1
  • 5
  • 13
  • can you show your layout file. adjustResize should be what you are looking for – peshkira Apr 04 '14 at 16:46
  • It's just resize my button. Maybe it's because the 2 Imageviews behind the views? – Ori Seri Apr 05 '14 at 07:56
  • see here: [enter link description here](http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard/34263560#34263560) –  Dec 14 '15 at 12:40

1 Answers1

-1

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

Technivorous
  • 1,603
  • 2
  • 15
  • 22