简体   繁体   中英

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"
           />
   <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" />

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM