86

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. Please, suggest me some way of doing it. Thanks in advance.

Juan José Melero Gómez
  • 2,617
  • 1
  • 16
  • 34
cavallo
  • 4,124
  • 9
  • 36
  • 59

17 Answers17

59

Set windowSoftInputMode property to adjustPan and adjustResize

<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>
CopsOnRoad
  • 109,635
  • 30
  • 367
  • 257
jeet
  • 27,861
  • 6
  • 48
  • 52
  • 34
    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
  • 112,868
  • 50
  • 288
  • 373
jency
  • 367
  • 2
  • 3
24

Use this code in onCreate() method:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Bobs
  • 21,870
  • 33
  • 134
  • 221
17

only

android:windowSoftInputMode="adjustResize"

in your activity tag inside Manifest file will do the trick

Bhargav Thanki
  • 4,552
  • 2
  • 31
  • 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,338
  • 13
  • 30
  • 44
Dayanand Waghmare
  • 2,511
  • 1
  • 18
  • 25
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
  • 5,963
  • 3
  • 34
  • 37
cavallo
  • 4,124
  • 9
  • 36
  • 59
  • 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,297
  • 22
  • 24
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
  • 6,244
  • 4
  • 21
  • 27
  • 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,190
  • 5
  • 42
  • 85
Dila Gurung
  • 1,450
  • 18
  • 22
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
  • 2,874
  • 2
  • 22
  • 25
2

I solve this by adding code into manifest:

<activity android:name=".Login"
        android:fitsSystemWindows="true"
        android:windowSoftInputMode="stateHidden|adjustPan"
</activity>
Sandeep Sankla
  • 1,140
  • 10
  • 19
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
  • 109,635
  • 30
  • 367
  • 257
0

This works like a charm for me

getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
droidchef
  • 1,930
  • 14
  • 30
0

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

Mahesh
  • 1,155
  • 1
  • 13
  • 21
-2

This will definitely work for you.

android:windowSoftInputMode="adjustPan"

sanjay kumar
  • 33
  • 1
  • 2