110

I have a <ScrollView> layout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_scrollview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/input_one"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:inputType="number" >

         <EditText
            android:id="@+id/input_two"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:inputType="number" >

         <EditText
            android:id="@+id/input_three"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:inputType="number" >

          <Button
            android:id="@+id/ok_btn"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"
            android:text="@string/ok_str" />

      </LinearLayout>
</ScrollView>

As you see above, the simple layout consists of three input fields and an "Ok" button.

I run my app with the above layout, when I tap on the 1st input field (@+id/input_one), the soft keyboard will pop up from the bottom of the screen, it hides the 3rd input field and the "Ok" button.

Since I use <ScrollView> , I thought I can scroll the page up in order to see the 3rd input field and "Ok" button which are hidden by the soft keyboard, but the page is not scrollable. Why? How to get rid of it? basically, i would like to see every input fields and "Ok" button even the soft keyboard popped up.

Evan
  • 2,282
  • 2
  • 19
  • 21
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
  • 1
    remove the , LinearLayout should be your outer layout, it will work, i hope even if the sofkeyboard pop up . – aalionline Apr 03 '12 at 07:51
  • 1
    @pakshaheen That won't fix the problem when scrollview is required. – Luten Dec 28 '16 at 07:03
  • here is the working code. https://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible/44242034#44242034 – Venkat May 29 '17 at 12:05

10 Answers10

136

I fixed the problem by defining the following attribute in <activity> of AndroidManifest.xml

android:windowSoftInputMode="adjustResize"
Saharsh
  • 383
  • 2
  • 11
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
  • 13
    You don't need stateVisible. That will make the soft keyboard appear when the app is launched even when the user is not focused on a EditText – RajV Aug 24 '18 at 21:32
  • 1
    it's autometically open keyboard even there is not edittext – Mr X Dec 21 '18 at 05:49
39

Ok, I have searched several hours now to find the problem, and I found it.

None of the changes like fillViewport="true" or android:windowSoftInputMode="adjustResize" helped me.

I use Android 4.4 and this is the big mistake:

android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"

Somehow, the Fullscreen themes prevent the ScrollViews from scrolling when the SoftKeyboard is visible.

At the moment, I ended up using this instead:

android:theme="@android:style/Theme.Black.NoTitleBar

I don't know how to get rid of the top system bar with time and battery display, but at least I got the problem.

Hope this helps others who have the same problem.

EDIT: I got a little workaround for my case, so I posted it here:

I am not sure if this will work for you, but it will definitely help you in understanding, and clear some things up.

EDIT2: Here is another good topic that will help you to go in the right direction or even solve your problem.

Community
  • 1
  • 1
qweret
  • 893
  • 10
  • 16
  • 1
    +1 In my case the status bar was hidden by a 3rd party lib in code: `getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);` – de. Dec 06 '16 at 22:14
  • @qweret What if I need both of them? Full screen and scrolling. – Prabs Apr 26 '17 at 12:27
  • @Prabs Did you find any solution? I also want both Full Screen and scrolling. – Johny May 09 '17 at 14:25
  • @Johny Nope. For now I'm using full screen for entire app except that activity with scrolling3. – Prabs May 10 '17 at 04:31
  • @Prabs The only solution I thought is have transparent status bar but in my case is stil an issue because I want to support API >= 16 . Do you have any idea? – Johny May 10 '17 at 07:38
20

For me the only thing that works is put in the activity in the manifest this atribute:

android:windowSoftInputMode="stateHidden|adjustPan"

To not show the keyboard when opening the activity and don't overlap the bottom of the view.

14

put this inside your Manifest like this in No fullscreen Mode

android:windowSoftInputMode="stateVisible|adjustPan" 

in your manifest

<activity
    android:windowSoftInputMode="stateVisible|adjustPan"
    android:name="com.example.patronusgps.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66
user3594530
  • 419
  • 4
  • 9
  • 1
    I've tried this but unfrotunately, no luck at all... However, the root view is **not** a `ScrollView`, but a `RelativeLayout` which contains a `LinearLayout` which then contains a `ScrollView` – James Heald Oct 02 '17 at 17:28
11

In your Manifest define windowSoftInputMode property:

<activity android:name=".MyActivity"
          android:windowSoftInputMode="adjustNothing">
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
7

check out this.

<activity android:name=".Calculator"
    android:windowSoftInputMode="stateHidden|adjustResize" 
    android:theme="@android:style/Theme.Black.NoTitleBar">
</activity>
Alp Altunel
  • 3,324
  • 1
  • 26
  • 27
Ravi1187342
  • 1,247
  • 7
  • 14
2

You can try using the following code to solve your problem:

 <activity
     android:name=".DonateNow"
     android:label="@string/title_activity_donate_now"
     android:screenOrientation="portrait"
     android:theme="@style/AppTheme"
     android:windowSoftInputMode="stateVisible|adjustPan">
 </activity>
Grant Miller
  • 27,532
  • 16
  • 147
  • 165
2

This only worked for me:

android:windowSoftInputMode="adjustPan"
blueware
  • 5,205
  • 1
  • 40
  • 60
2

Also if you want to do that programmatically just add the below line to the onCreate of the activity.

getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | 
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
ucMedia
  • 4,105
  • 4
  • 38
  • 46
0

well, the simplest answer I tried is just removing your code which makes the activity go full screen. I had a code like this which was responsible for making my activity go fullscreen :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

    getWindow().setFlags(
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
    );
}

I just removed my code and it works completely fine although if you want to achieve this with your fullscreen on then you'll have to try some other methods

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41