11

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"
           />
Jaume
  • 3,672
  • 19
  • 60
  • 119
  • See also https://stackoverflow.com/questions/16411056/how-to-adjust-layout-when-soft-keyboard-appears. – CoolMind Oct 31 '21 at 21:24

3 Answers3

11
   <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" />
wadali
  • 2,221
  • 1
  • 20
  • 38
9

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.

Community
  • 1
  • 1
Levite
  • 17,263
  • 8
  • 50
  • 50
  • 1
    Thank you. Turns out if you are modifying systemUiVisibility with flag View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, you should be using setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) to set the flag adjustResize. Do not forget to set android:fitsSystemWindows="true" on the root layout (under scrollview if you are using one). – farhanjk Mar 10 '19 at 07:01
  • 1
    `SOFT_INPUT_ADJUST_RESIZE` is deprecated – Konstantin Konopko Mar 01 '21 at 17:35
1

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.

AggelosK
  • 4,313
  • 2
  • 32
  • 37
  • @Jaume See this previous SO post: [link](http://stackoverflow.com/questions/4605076/androidwindowsoftinputmode-adjustresize-when-ive-already-have-scrollview-in). Hope it helps:) – AggelosK Jul 10 '12 at 19:50