5

My problem is when keyboard is open scrollview is not working. Means basically when I have Theme android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" scrollview is not working When I have theme android:theme="@android:style/Theme.Black.NoTitleBar" and remove this from manifest android:windowSoftInputMode="adjustResize" then scrollview is working perfectly. But my app theme is android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen".

This is my activity

package com.example.demo;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

}

This is my xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

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

            <Button

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="btn1" />

            <Button

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="btn2" />

            <Button

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="btn3" />

            <Button

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="btn4" />

            <Button

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="btn5" />

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <Button

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="btn1" />

            <Button

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="btn2" />

            <Button

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="btn3" />

            <Button

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="btn4" />

            <Button

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="btn5" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

This is my manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.demo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        <activity
            android:name="com.example.demo.MainActivity"
            android:windowSoftInputMode="adjustResize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

please help me. Thanks in advance.

Lavanya
  • 3,903
  • 6
  • 31
  • 57
user
  • 245
  • 1
  • 4
  • 12
  • Did you try to remove the `RelativeLayout` from your layout xml? That one does not seem to have any purpose. –  Nov 08 '13 at 12:55
  • 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:06

4 Answers4

9

I got the same problem. The fullcreen mode prevents the scrolling.

In concrete, I tested several FLAGS and LAYOUTS. These are working and don't prevent scrolling:

View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
View.SYSTEM_UI_FLAG_FULLSCREEN
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
View.SYSTEM_UI_FLAG_LAYOUT_STABLE

These are preventing the scrolling and do not work:

View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

So I got a workaround finally, took me some days, but it works!

  1. Choose a theme, that is not fullscreen in manifest.xml, e.g.:

    android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
    
  2. Add this code, that makes your activity fullscreen

    private static View systemUIView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.rootlayout); //your layout with the scrollview
    
        // hide the native android navigation and status bar
        systemUIView = getWindow().getDecorView();
        hideSystemUI();
    
        if (android.os.Build.VERSION.SDK_INT >= 19) {
            getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
                    new OnSystemUiVisibilityChangeListener() {
                        @Override
                        public void onSystemUiVisibilityChange(int visibility) {
                            if (visibility == 0) {
                                hideSystemUI();
                            }
                        }
                    });
        }
    
    // ... here comes my whole code...      
    }
    
    @Override
    public void onResume() {
        super.onResume();
        hideSystemUI();
    }
    
    public void hideSystemUI() {
        systemUIView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
    

The systembar and navigation bar disappears. The reason for this is, because I have set IMMERSIVE_STICKY. It is whole lot of work to test it all around. I hope this helps you all, or atleast gives you the right direction.

Remember, that a Fullscreen-Theme will always prevent you from scrolling while the softkeyboard is up. I am referencing to Android 4.4(KitKat).

Roc Boronat
  • 11,395
  • 5
  • 47
  • 59
qweret
  • 893
  • 10
  • 16
  • Thanks. As you said the fullscreen prevents the scroll. What I did was set to false the android:windowFullscreen put to true the windowNoTitle to disappear the actionbar. – thalespf Sep 28 '14 at 20:25
  • This is good for full screen. What about keeping the ActionBar and hiding only the status bar? I couldn't find a solution for that yet. – zeeshan Jun 12 '16 at 10:42
  • As it is the bug in Android OS, when you make the Activity FullScreen and also use ScrollView or NestedScrollView on open soft keyboard, scrolling not working.As already bug reported at Android IssueTracker but not fix yet. – Asad Mukhtar Jun 18 '19 at 11:40
0

apply the scroll view with parent layout.

try this it may help you.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

        <Button

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="btn1" />

        <Button

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="btn2" />

        <Button

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="btn3" />

        <Button

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="btn4" />

        <Button

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="btn5" />

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <Button

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="btn1" />

        <Button

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="btn2" />

        <Button

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="btn3" />

        <Button

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="btn4" />

        <Button

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="btn5" />
    </LinearLayout>
</ScrollView>
balaji koduri
  • 1,321
  • 9
  • 25
0

In Manifest:

android:windowSoftInputMode="adjustPan|stateVisible"

In layout xml bottom of all child layout of scrollview set one textview, such as

<ScrollView
android:id="@+id/driverLoginScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="false"
android:scrollbars="none">
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="50dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical">
    .
    .
    .
   <TextView
   android:layout_width="match_parent"
   android:layout_height="100dp"
   android:focusable="false"
   android:textIsSelectable="false" />
   </LinearLayout>
</ScrollView>
Bharat Sonawane
  • 162
  • 3
  • 10
0

It won't work if you're using fullscreen, so add a space under "RL" and set your height to ~ 400 dp.

mbarut
  • 1