Jan
Jan

Reputation: 3401

EditText being overlapped by the soft keyboard

Why is that when I press done on the keyboard or press the back button, the EditText isn't animated again to the top of the keyboard. So the 2nd time the keyboard appears the layout doesn't get resized.

Here's my xml:

<EditText
android:id="@+id/share_caption"
android:maxLines="1"
android:singleLine="true"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#ffffffff"
android:textSize="18sp"
android:textCursorDrawable="@drawable/cursor_color"
android:textColor="#ff696969"/>

Apparently setting the gravity is the cause. But this is essential if you want to center the text or the hint.

-EDIT-

After reading the docs about windowSoftInputMode and adjustPan seems to be fit for the job but It doesn't work with the android:gravity="center"

Upvotes: 0

Views: 128

Answers (3)

NarenderNishad
NarenderNishad

Reputation: 1068

use the following attribute in activity of AndroidManifest.xml

<activity
            android:name="com.domain.app.MyActivity"
            android:windowSoftInputMode="adjustResize|stateHidden"
            android:configChanges="keyboard|orientation|screenSize"
            android:screenOrientation="portrait" />

Upvotes: 0

Fahim
Fahim

Reputation: 12358

define the following attribute in <activity> of AndroidManifest.xml

android:windowSoftInputMode="stateVisible|adjustResize"

Upvotes: 0

Rajen Raiyarela
Rajen Raiyarela

Reputation: 5636

add following line to activity tag in android manifest file:

android:windowSoftInputMode="adjustPan|adjustResize"

The one you added is for handling of config changes yourself.

Example:

<activity
   android:name=".MainActivity"
   android:label="@string/app_name"
   android:screenOrientation="portrait"
   android:windowSoftInputMode="adjustPan|adjustResize" >
   <intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
</activity>

Upvotes: 1

Related Questions