108

我有一个<ScrollView>布局:

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

正如您在上面看到的,简单的布局由三个输入字段和一个“确定”按钮组成。

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

自从我使用以来<ScrollView>,我想我可以向上滚动页面以查看软键盘隐藏的第三个输入字段和“确定”按钮,但页面不可滚动。为什么?如何摆脱它?基本上,我希望看到每个输入字段和“确定”按钮,即使软键盘弹出。

4

10 回答 10

132

<activity>我通过在AndroidManifest.xml中定义以下属性来解决问题

android:windowSoftInputMode="adjustResize"
于 2012-04-03T08:35:26.843 回答
39

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

没有任何变化喜欢fillViewport="true"android:windowSoftInputMode="adjustResize"帮助我。

我使用 Android 4.4,这是一个大错误

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

不知何故,当 SoftKeyboard 可见时,全屏主题会阻止 ScrollViews 滚动。

此刻,我最终改用了这个:

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

我不知道如何摆脱带有时间和电池显示的顶部系统栏,但至少我遇到了问题。

希望这可以帮助其他有同样问题的人。

编辑:我的情况有一些解决方法,所以我把它贴在这里

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

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

于 2014-02-26T17:22:38.270 回答
21

对我来说,唯一有效的就是将这个属性放在清单中的活动中:

android:windowSoftInputMode="stateHidden|adjustPan"

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

于 2016-02-11T17:20:01.177 回答
15

像这样在无全屏模式下将其放入您的清单中

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>
于 2014-05-09T00:04:14.033 回答
12

在您的Manifest定义windowSoftInputMode属性中:

<activity android:name=".MyActivity"
          android:windowSoftInputMode="adjustNothing">
于 2012-04-03T07:56:55.290 回答
8

看看这个。

<activity android:name=".Calculator"
    android:windowSoftInputMode="stateHidden|adjustResize" 
    android:theme="@android:style/Theme.Black.NoTitleBar">
</activity>
于 2012-04-03T08:03:17.980 回答
3

这只对我有用:

android:windowSoftInputMode="adjustPan"
于 2017-07-25T10:18:27.813 回答
2

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

getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | 
            WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE );
于 2019-06-03T12:25:39.063 回答
1

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

 <activity
     android:name=".DonateNow"
     android:label="@string/title_activity_donate_now"
     android:screenOrientation="portrait"
     android:theme="@style/AppTheme"
     android:windowSoftInputMode="stateVisible|adjustPan">
 </activity>
于 2016-07-24T13:38:49.033 回答
0

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

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

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

我刚刚删除了我的代码,它工作得很好,但如果你想在全屏模式下实现这一点,那么你将不得不尝试其他一些方法

于 2019-10-12T13:34:43.880 回答