5

我的问题是当键盘打开时滚动视图不起作用。基本上意味着当我有主题时android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 滚动视图不起作用当我有主题android:theme="@android:style/Theme.Black.NoTitleBar"并从清单中删除它时, android:windowSoftInputMode="adjustResize"滚动视图工作正常。但我的应用主题是android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen".

这是我的活动

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);
    }

}

这是我的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>

这是我的清单

<?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>

请帮我。提前致谢。

4

4 回答 4

9

我遇到了同样的问题。全屏模式可防止滚动。

具体来说,我测试了几个标志和布局。这些正在工作并且不会阻止滚动:

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

这些阻止滚动并且不起作用:

View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

所以我终于找到了一个解决方法,花了我几天的时间,但它有效!

  1. 在 manifest.xml 中选择一个不是全屏的主题,例如:

    android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
    
  2. 添加此代码,使您的活动全屏

    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);
    }
    

系统栏和导航栏消失。这样做的原因是,因为我设置了 IMMERSIVE_STICKY。对它进行全面测试是一项艰巨的工作。我希望这对你们所有人都有帮助,或者至少给你们一个正确的方向。

请记住,全屏主题将始终阻止您在软键盘启动时滚动。我指的是 Android 4.4(KitKat)。

于 2014-02-27T11:32:47.797 回答
0

应用带有父布局的滚动视图。

试试这个它可能会帮助你。

<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>
于 2013-11-08T13:55:57.583 回答
0

在清单中:

android:windowSoftInputMode="adjustPan|stateVisible"

在scrollview的所有子布局的layout xml底部设置一个textview,如

<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>
于 2017-02-14T07:59:39.113 回答
0

如果您使用全屏,它将不起作用,因此在“RL”下添加一个空格并将您的高度设置为 ~ 400 dp。

于 2020-08-25T02:03:36.800 回答