89

I have a login screen with two EditTexts and a login button in my layout. The problem is that, when I start typing, the soft keyboard is shown and covers the login button. How can I push the layout up or above the keyboard when it appears?

I do not want to use a ScrollView, just want to implement it without scrolling down. How can that be done?

starball
  • 20,030
  • 7
  • 43
  • 238
cavallo
  • 4,414
  • 9
  • 39
  • 61

17 Answers17

62

Set windowSoftInputMode property to adjustPan and adjustResize

<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
jeet
  • 29,001
  • 6
  • 52
  • 53
  • 36
    This didn't work out of the box, but changing it to `` got it working. – nickiaconis Aug 26 '14 at 20:20
  • 2
    Mention which Android version you are using. Some answers may be totally useless on some versions. – Josh Aug 12 '15 at 13:25
  • as @nickiaconis said, I dont need 'adjustPan' parameter and it works for me, thank you – danisupr4 Feb 26 '16 at 04:23
  • Is there an equivalent available for Xamarin.Forms portable project? so I don't have to do this for each individual target platform. – user20358 Jun 13 '16 at 14:50
  • Only using `adjustPan` did the trick for me. Worked like charm :) Many thanks! – Atul Jul 19 '16 at 07:17
  • 6
    The setting must be one of the values listed in the following table, or a combination of one "state..." value plus one "adjust..." value. Setting multiple values in either group — multiple "state..." values, for example — has undefined results. https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft – EmJiHash Nov 22 '16 at 08:17
  • This won't work if `windowFullscreen` is enabled in theme – Prabs Mar 27 '17 at 06:19
  • This doesn't work if all views have fixed sizes. When I made weight `1` and height `0dp` on one of the view, my activity resized on soft input. – soshial Oct 31 '17 at 12:14
35

Try this in the android manifest file corresponding to the activity.

<activity android:windowSoftInputMode="adjustPan"> </activity>
Kev
  • 118,037
  • 53
  • 300
  • 385
jency
  • 377
  • 2
  • 3
27

Use this code in onCreate() method:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Bob
  • 22,810
  • 38
  • 143
  • 225
18

only

android:windowSoftInputMode="adjustResize"

in your activity tag inside Manifest file will do the trick

Bhargav Thanki
  • 4,924
  • 2
  • 37
  • 43
  • I am using ConstraintLayout, this solution does not work for me. – Karan Sharma Sep 26 '19 at 07:27
  • At the time of writing this answer, ConstraintLayout was not added in Android layouts. You please find any other solution on this thread that suits you best. And surely I will update my answer for ConstraintLayout once I get the time. Thanks for reporting – Bhargav Thanki Sep 26 '19 at 10:42
13

Put this line in activity declaration time in manifest.xml

<android:windowSoftInputMode="adjustPan">
Darin Kolev
  • 3,401
  • 13
  • 31
  • 46
Dayanand Waghmare
  • 2,979
  • 1
  • 22
  • 27
10
android:fitsSystemWindows="true"

add property on main layout of layout file and

android:windowSoftInputMode="adjustResize"

add line in your Manifest.xml file on your Activty

its perfect work for me.

10

I somehow achieved this by knowing the status of the soft keyboard on the device. i move the layout to y position when the keyboard is shown and moved back to its original position when not shown. this works fine, followed this guidelines.

Frank Nguyen
  • 6,493
  • 3
  • 38
  • 37
cavallo
  • 4,414
  • 9
  • 39
  • 61
  • 2
    I am able to move the layout up when keyboard shows, but unable to move to its original position while key board hides, can u help me in this. – Kishore Aug 17 '12 at 10:21
6

Put this in your activity declaration in manifest file <activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>

or if you want you can add in onCreate() method of your activity

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
  • 2
    Manifest code is wrong, this way behavior is undefined (you set two conflict values, see offdoc: https://developer.android.com/guide/topics/manifest/activity-element.html, `android:windowSoftInputMode` description). @kiwicomb123, choose one parameter or the system will choose for you (and this choice can change on another device / API verision) – kpower Sep 08 '17 at 16:51
3

This is all that is needed:

<activity android:windowSoftInputMode="adjustResize"> </activity>
Bolling
  • 3,954
  • 1
  • 27
  • 29
3

I solve this by adding code into manifest:

<activity android:name=".Login"
        android:fitsSystemWindows="true"
        android:windowSoftInputMode="stateHidden|adjustPan"
</activity>
Sandeep Sankla
  • 1,250
  • 12
  • 21
2

Accoding to this guide, the correct way to achieve this is by declaring in your manifest:

<activity name="EditContactActivity"
        android:windowSoftInputMode="stateVisible|adjustResize">

    </activity>
David_E
  • 7,130
  • 4
  • 26
  • 29
  • It looks like stateVisible will cause it to open when the activity starts, so it's not necessary to actually push the keyboard up. – CodyEngel Mar 31 '17 at 16:17
2

When the softkeyboard appears, it changes the size of main layout, and what you need do is to make a listener for that mainlayout and within that listener, add the code scrollT0(x,y) to scroll up.

Akeshwar Jha
  • 4,516
  • 8
  • 52
  • 91
Dila Gurung
  • 1,726
  • 21
  • 26
2

If you are working with xamarin, you can put this code WindowSoftInputMode =Android.Views.SoftInput.AdjustPan | Android.Views.SoftInput.AdjustResize in activity attribute of the MainActivity class. For example, now the activity attribute will look like below

    [Activity(WindowSoftInputMode =Android.Views.SoftInput.AdjustPan | Android.Views.SoftInput.AdjustResize)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
    {
        //some code here.
    }
Tushar patel
  • 3,279
  • 3
  • 27
  • 30
1

You should use

android:windowSoftInputMode="adjustPan|stateHidden"

in your AndroidManifest.xml file where you are declaring your activity. This will adjust your layout contents, when keyboard is shown in the layout.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
0

This works like a charm for me

getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
droidchef
  • 2,237
  • 1
  • 18
  • 34
0

Make use of Relative layout it will adjust the view so that you can see that view while typing the text

Mahesh
  • 1,257
  • 1
  • 14
  • 24
-2

This will definitely work for you.

android:windowSoftInputMode="adjustPan"

sanjay kumar
  • 33
  • 1
  • 2