Jaume
Jaume

Reputation: 3780

android resize layout when keyboard appears

I would like to reposition layout when keyboard appears, for example when editing a text field, in order to get visibility on focused field. I tried windowSoftInputMode but I cannot get any difference. How to reach it? Thank you.

<activity 
            android:name="com.xxxx.projecte1.TabBar_Activity"      
            android:theme="@android:style/Theme.NoTitleBar"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:windowSoftInputMode="adjustResize"
           />

Upvotes: 11

Views: 19974

Answers (3)

Jaswinder
Jaswinder

Reputation: 2289

   <activity
        android:name=".WActivity"
        android:configChanges="orientation|keyboard|keyboardHidden|screenSize|screenLayout|uiMode"
        android:icon="@drawable/navigation_two"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/appTheme"
        android:windowSoftInputMode="adjustResize" />

Upvotes: 11

Levite
Levite

Reputation: 17617

For anyone else who might have a similar problem:

What fixed it in my case was just putting

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

into my activity's onCreate method.

Without any xml changes whatsoever, since those did not work for me whatsoever, but this worked right away like a charm. Although an xml solution seems nicer to me, even the same parameter did not work.

Sharing it since I did not find a quick and easy fix myself online.

Upvotes: 9

AggelosK
AggelosK

Reputation: 4341

I believe the problem is this line

android:configChanges="keyboardHidden|orientation|screenSize"

in your code. This line tells the Android that your Activity will handle this 3 events on its own. If you remove this line, i believe you will have the desired effect.

See here for the configChanges attribute.

Upvotes: 1

Related Questions