0

This question may be similar to this and this, but they didn't solve my problem. I have a login UI, which looks like this:

enter image description here

When I click the Username field, it becomes like this:

enter image description here

As you can see here, the Password field is covered by the soft keyboard, and after input the Username, you have to first close the soft keyboard and then click the Password field to type in the password, which is not user friendly. How to avoid the Password field being covered by the soft keyboard so that the user can type in the password directly. Below is the layout of this UI.

 <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="eda397.group10.navigator.MainActivity$PlaceholderFragment" >

<ImageView
    android:id="@+id/logo"
    android:layout_width="125dp"
    android:layout_height="125dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginTop="24dp"
    android:src="@drawable/ic_launcher" />


<Button
    android:id="@+id/register_button"
    android:layout_width="85dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/login_username"
    android:layout_marginBottom="65dp"
    style="@style/CustomStyleButton" 
    android:text="@string/button_register" />

<EditText
    android:id="@+id/login_username"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_alignLeft="@+id/login_password"
    android:layout_alignRight="@+id/login_password"
    android:layout_centerVertical="true"
    android:background="#d8d8d8"
    android:ems="10"
    android:hint="@string/username_message" >

</EditText>

<EditText
    android:id="@+id/login_password"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_below="@+id/login_username"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="17dp"
    android:background="#d8d8d8"
    android:ems="10"
    android:hint="@string/password_message"
    android:inputType="textPassword" />

<Button
    android:id="@+id/login_button"
    android:layout_width="85dp"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/register_button"
    android:layout_alignBottom="@+id/register_button"
    android:layout_alignLeft="@+id/login_username"
    style="@style/CustomStyleButton" 
    android:text="@string/button_send" />

</RelativeLayout>
Community
  • 1
  • 1
betteroutthanin
  • 7,148
  • 8
  • 29
  • 48

2 Answers2

0

In your AndroidManifest.xml, in your activity declaration, you need to set windowSoftInputMode as below:

<activity
    android:name="..."
    android:windowSoftInputMode="adjustResize">
</activity>

This solution may not work as you are using a relative layout. You may consider changing to linear layouts and use windowSoftInputMode or you can try to change your layout gravity like that:

<RelativeLayout
    ...
    android:layout_gravity="bottom" >
Distwo
  • 11,569
  • 8
  • 42
  • 65
0

If you just want to make it easy for the user to get from the Username to the Password field, you could add imeOptions to login_username:

<EditText
    android:id="@+id/login_username"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_alignLeft="@+id/login_password"
    android:layout_alignRight="@+id/login_password"
    android:layout_centerVertical="true"
    android:background="#d8d8d8"
    android:ems="10"
    android:hint="@string/username_message"
    android:imeOptions="actionNext" >

This won't change the keyboard covering the screen, but if you wanted to fix that, the answers you mentioned in your question should've sufficed.

Tomty
  • 1,962
  • 1
  • 22
  • 37