1

I'm not sure what title should I put in here but here is the question.

I want my fields to be attached to the bottom of the screen when keyboard is out. When there is no keyboard, I want my fields to be at the center of the screen.

Basically 1 and 2 are spaces and I want Space I to be first candidate on squeezing when keyboard is out.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:fitsSystemWindows="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v4.widget.Space
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/walletPasswordEditLayout"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:layout_marginStart="16dp">

            <android.support.design.widget.TextInputEditText
                style="@style/AppEditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"/>

        </android.support.design.widget.TextInputLayout>

        <Button
            style="@style/AppButton.Black"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:layout_marginStart="16dp"
            android:text="@string/unlock_button"/>

        <android.support.v4.widget.Space
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    </LinearLayout>

</FrameLayout>

enter image description here

nutella_eater
  • 3,102
  • 1
  • 24
  • 36
  • You can check if the keyboard is visible using this answer: https://stackoverflow.com/questions/4745988/how-do-i-detect-if-software-keyboard-is-visible-on-android-device and then change the layout accordingly – Anuraag Baishya Mar 23 '18 at 08:05

2 Answers2

0

add this in your activity

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Kasia Gogolek
  • 3,199
  • 4
  • 29
  • 48
Silva
  • 172
  • 9
0

Please check this Link:

You can add in your menifest for the activity you want to prevent such issue. Also make sure if you are having a bit more content use scrollView as a parent. And soft input mode as "adjustResize"

android:windowSoftInputMode="adjustResize" 

or

android:windowSoftInputMode="adjustPan"
Deep Patel
  • 2,258
  • 2
  • 12
  • 26