-1

Hi i have the following layout in activity.xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_change_password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:layout_marginTop="0dp"
tools:context="com.kdpl.motodriver.ChangePassword">
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar1"
    android:layout_width="fill_parent"
    android:layout_height="58dp"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:titleTextColor="#ffffff">
    <Button
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:background="@drawable/back_arrow" android:onClick="onBackPressed" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/change_password_header"
        android:layout_gravity="center"
        android:id="@+id/toolbar_title"
        style="@style/TitleStyle"/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"
    android:layout_below="@+id/toolbar1"
    android:id="@+id/txt1">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:id="@+id/txtOldPIN"
        android:hint="@string/txt_old_pin"
        android:maxLength="4"
        android:paddingLeft="10dp"
        android:textColor="#ffffff"
        android:inputType="numberPassword"
        android:textColorHint="@color/lightGray"
        android:gravity="center_vertical"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:layout_below="@+id/txt1"
    android:id="@+id/txt2">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:paddingLeft="10dp"
        android:textColor="#ffffff"
        android:id="@+id/txtNewPin"
        android:inputType="numberPassword"
        android:maxLength="4"
        android:hint="@string/txt_new_pin"
        android:textColorHint="@color/lightGray"
        android:gravity="center_vertical"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:layout_below="@+id/txt2"
    android:id="@+id/txt3">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:paddingLeft="10dp"
        android:id="@+id/txtConfirmPin"
        android:inputType="numberPassword"
        android:maxLength="4"
        android:textColor="#ffffff"
        android:layout_below="@+id/txt2"
        android:hint="@string/txt_confirm_new_pin"
        android:textColorHint="@color/lightGray"
        android:gravity="center_vertical"/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_alignParentBottom="true">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnChangePIN"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/my_custom_btn_1"
        android:layout_below="@id/txt3"
        style="@style/buttonStyle"
        android:text="@string/txt_change_pin"
        android:enabled="false"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnCancelPIN"
        android:layout_marginTop="20dp"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/my_custom_btn_1"
        android:layout_below="@id/btnChangePIN"
        style="@style/buttonStyle"
        android:text="@string/btn_cancel_text" />
</LinearLayout>

I have added the following line in Manifest.xml

  <activity android:name=".ChangePassword"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        />

But the Buttons align parent bottom hides when keyboard open. Layout does not resize itself.

What i am missing ?

Updated View

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_change_password"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:layout_marginTop="0dp"
tools:context="com.kdpl.motodriver.ChangePassword">
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar1"
    android:layout_width="fill_parent"
    android:layout_height="58dp"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:titleTextColor="#ffffff">
    <Button
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:background="@drawable/back_arrow" android:onClick="onBackPressed" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/change_password_header"
        android:layout_gravity="center"
        android:id="@+id/toolbar_title"
        style="@style/TitleStyle"/>
</android.support.v7.widget.Toolbar>
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/toolbar1">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_below="@+id/toolbar1"
            android:id="@+id/txt1">
            <EditText
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:id="@+id/txtOldPIN"
                android:hint="@string/txt_old_pin"
                android:maxLength="4"
                android:paddingLeft="10dp"
                android:textColor="#ffffff"
                android:inputType="numberPassword"
                android:textColorHint="@color/lightGray"
                android:gravity="center_vertical"/>
        </android.support.design.widget.TextInputLayout>
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_below="@+id/txt1"
            android:id="@+id/txt2">
            <EditText
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:paddingLeft="10dp"
                android:textColor="#ffffff"
                android:id="@+id/txtNewPin"
                android:inputType="numberPassword"
                android:maxLength="4"
                android:hint="@string/txt_new_pin"
                android:textColorHint="@color/lightGray"
                android:gravity="center_vertical"/>
        </android.support.design.widget.TextInputLayout>
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_below="@+id/txt2"
            android:id="@+id/txt3">
            <EditText
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:paddingLeft="10dp"
                android:id="@+id/txtConfirmPin"
                android:inputType="numberPassword"
                android:maxLength="4"
                android:textColor="#ffffff"
                android:layout_below="@+id/txt2"
                android:hint="@string/txt_confirm_new_pin"
                android:textColorHint="@color/lightGray"
                android:gravity="center_vertical"/>
        </android.support.design.widget.TextInputLayout>
    </LinearLayout>
</ScrollView>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingBottom="10dp"
    android:layout_alignParentBottom="true">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnChangePIN"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/my_custom_btn_1"
        android:layout_below="@id/txt3"
        style="@style/buttonStyle"
        android:text="@string/txt_change_pin"
        android:enabled="false"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnCancelPIN"
        android:layout_marginTop="20dp"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:layout_centerHorizontal="true"
        android:background="@drawable/my_custom_btn_1"
        android:layout_below="@id/btnChangePIN"
        style="@style/buttonStyle"
        android:text="@string/btn_cancel_text" />
</LinearLayout>

I have updated my view to add scrollview in between toolbar and buttons. I have also added getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); in my activity as suggested.. It works but not perfectly. Now Buttons overlap the views in scroll view. Attached is image My App Images

Rajeev Kumar
  • 4,901
  • 8
  • 48
  • 83

5 Answers5

1

Add parent layout is Scroll view

   <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >
   </ScrollView >
Nikunj Paradva
  • 15,332
  • 5
  • 54
  • 65
1

An alternate answer would be to add

android:windowSoftInputMode="adjustResize"

in your root layout

Arthur Attout
  • 2,701
  • 2
  • 26
  • 49
0

Why not use the CoordinateLayout as the parent layout. If it can work for snacks it must work for the keyboard as well

Flash
  • 1,105
  • 14
  • 16
0

Add this code in your Activity:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
-1

Please use adjustPan instead of adjustResize as follows :

<activity android:name=".ChangePassword"
        android:configChanges="orientation|keyboardHidden"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan" />
Suraj Makhija
  • 1,376
  • 8
  • 16