Dev01
Dev01

Reputation: 4222

android edittext becomes partically visible on keyboard open

I am having problem when keyboard opens up, the edit text appears partially eg not full view.

Screenshot:

enter image description here

Here is layout code:

<ScrollView 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:background="@color/lightgreen"
    android:fillViewport="true"
    android:padding="20dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/lightgreen"
        android:orientation="vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_mobilenumber"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_mobile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="phone" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_password"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_password_confirm"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_password_confirm"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_fullname"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:ignore="TextFields" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_email"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textEmailAddress" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:text="@string/str_city"
            android:textSize="16sp" />

        <Spinner
            android:id="@+id/reg_city"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:entries="@array/cities_array"
            android:prompt="@string/str_city" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/str_zip"
            android:textSize="16sp" />

        <EditText
            android:id="@+id/reg_zip"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:inputType="phone" />

        <Button
            android:id="@+id/btnRegister"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="actionRegister"
            android:text="@string/str_register" />
    </LinearLayout>

</ScrollView>

Same problem happens with any edit text field that when keyboard oens, it doesnt appear fully. Is there any way to avoid this problem ?

Thanks

Upvotes: 2

Views: 2060

Answers (2)

stkent
stkent

Reputation: 20128

Check out the available attributes for the activity element, in particular, android:windowSoftInputMode. You could consider adding either adjustResize:

The activity's main window is always resized to make room for the soft keyboard on screen.

or adjustPan:

The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

depending on your specific requirements.

Example usage:

<activity android:windowSoftInputMode="adjustResize" />

This answer may also be useful to read.

Upvotes: 4

Mohammad Rahchamani
Mohammad Rahchamani

Reputation: 5220

the problem is there is not enough room for you layout and keyboard. you can scroll you view to prevent this problem. there are two ways of doing this :

"adjustResize"

The activity's main window is always resized to make room for the soft keyboard on screen.

"adjustPan"

The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

you should add this line to your activity tag inside manifest.xml

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

Upvotes: 4

Related Questions