Android 软键盘弹出时页面滚动

Android 软键盘弹出时页面滚动,android,android-layout,android-intent,android-scrollview,android-keypad,Android,Android Layout,Android Intent,Android Scrollview,Android Keypad,我有一个布局: <?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" >

我有一个
布局:

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

如上所述,简单布局由三个输入字段和一个“Ok”按钮组成

我使用上述布局运行我的应用程序,当我点击第一个输入字段(
@+id/input\u one
)时,软键盘将从屏幕底部弹出,它隐藏第三个输入字段和“Ok”按钮


由于我使用了
,我想我可以向上滚动页面,以便看到第三个输入字段和“Ok”按钮,它们被软键盘隐藏,但页面不可滚动。为什么?如何摆脱它基本上,我希望看到每个输入字段和“Ok”按钮,甚至软键盘弹出。

在您的
清单中
定义
windowSoftInputMode
属性:

<activity android:name=".MyActivity"
          android:windowSoftInputMode="adjustNothing">

看看这个

<activity android:name=".Calculator"
    android:windowSoftInputMode="stateHidden|adjustResize" 
    android:theme="@android:style/Theme.Black.NoTitleBar">
</activity>

我在AndroidManifest.xml的
中定义了以下属性,解决了这个问题

android:windowSoftInputMode="adjustResize"

好的,我已经搜索了几个小时来找到问题,我找到了

fillViewport=“true”
android:windowSoftInputMode=“adjustResize”
这样的更改对我都没有帮助

我使用安卓4.4,这是一个很大的错误:

不知何故,当软键盘可见时,全屏主题阻止滚动视图滚动

现在,我用这个来代替:

android:theme="@android:style/Theme.Black.NoTitleBar
我不知道如何摆脱带有时间和电池显示的顶部系统栏,但至少我遇到了问题

希望这能帮助其他有同样问题的人

编辑:我为我的案例找到了一些解决办法,所以我发布了:

我不确定这是否对你有用,但它肯定会帮助你理解,并澄清一些事情


EDIT2:是另一个很好的主题,它将帮助您朝着正确的方向前进,甚至解决您的问题

在非全屏模式下,像这样将其放入清单中

android:windowSoftInputMode="stateVisible|adjustPan" 
在你的舱单上

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

对我来说,唯一有效的方法是将此文件放入清单中的活动中:

android:windowSoftInputMode="stateHidden|adjustPan"

打开“活动”时不显示键盘,且不与视图底部重叠。

您可以尝试使用以下代码解决问题:

 <activity
     android:name=".DonateNow"
     android:label="@string/title_activity_donate_now"
     android:screenOrientation="portrait"
     android:theme="@style/AppTheme"
     android:windowSoftInputMode="stateVisible|adjustPan">
 </activity>

这只对我有用:

android:windowSoftInputMode="adjustPan"

另外,如果您希望以编程方式执行此操作,只需将下面的行添加到活动的onCreate中

getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | 
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );

我尝试过的最简单的答案就是删除使活动全屏显示的代码。我有一个这样的代码,负责使我的活动全屏显示:

if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.KITKAT){


我刚刚删除了我的代码,它工作得很好,不过如果你想在全屏上实现这一点,你必须尝试其他方法

删除,LinearLayout应该是你的外部布局,它会工作的,我希望即使sofkeyboard弹出。@pakshaheen在需要scrollview时也不会解决问题。以下是工作代码。@JacobRas请检查此链接:它的值为“adjustNothing”:)我也有同样的问题,但scrollview不能与adjustNothing一起工作:(你应该费心解释你的代码是做什么的,而不是仅仅发布一个单件代码作为答案。+1在我的例子中,状态栏被代码中的第三方库隐藏:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,WindowManager.LayoutParams.FLAG_全屏);
@qweret如果我同时需要它们怎么办?全屏和滚动。@Prabs你找到解决方案了吗?我也需要全屏和滚动。@Johny没有。现在我对整个应用程序使用全屏,除了滚动3的活动。@Prabs我认为唯一的解决方案是有透明的状态栏,但在我的情况下仍然是一个问题,因为我想支持API>=16。你有什么想法吗?我已经尝试过了,但没有成功,一点运气都没有……然而,根视图不是
滚动视图
,而是
相对视图
,它包含
线性布局
,然后包含
滚动视图
,你不需要状态可见。这将使软键盘看起来像是ar当应用程序启动时,即使用户没有关注edittext,它也会自动打开键盘,即使没有edittext
getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | 
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }