键盘不会在 EditText 上方推送布局

lnk*_*ree 0 mobile android android-layout

在我的应用程序中,我有以下布局:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <RelativeLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <EditText
            android:id="@+id/edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@color/text"
            android:gravity="center_horizontal"
            android:hint="@string/input_hint"
            android:inputType="textVisiblePassword"
            android:padding="@dimen/margin"
            android:singleLine="true"
            android:textColor="@color/input_text"
            android:textColorHint="@color/input_hint">
        </EditText>

    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

单击 EditText 时,键盘将包括 ActionBar 在内的屏幕向上推,以便 EditText 正好位于键盘上方。我想要的是只有 EditText 出现在键盘上,但上面的 FragmentContainer 保持完整“作为背景”。我通过在 AndroidManifest.xml 文件中使用 android: windowSoftInputMode = "adjustResize" 得到了一些,但我的应用程序是全屏的,这个标签显然不适用于全屏。

Ben*_* P. 5

据我所知,没有办法实现你所描述的。

这些是可供您选择的windowSoftInputMode

  • adjustNothing:当键盘出现时,窗口根本没有调整。这将阻止您fragment_container移动或调整大小,但也会导致键盘覆盖您的文本输入字段。

  • adjustResize:当键盘出现时,窗口垂直“缩小”。这将导致您fragment_container占用的空间少于键盘关闭时的空间,从而可能影响您的片段布局。

  • adjustPan:当键盘出现时,屏幕被向上“推”。这将导致您fragment_container的 顶部被屏幕边缘剪掉。

  • adjustUnspecified:允许系统在以上三个选项之间进行选择。

下面是一些(希望)有助于说明这些属性的图片。

键盘关闭

键盘关闭时的布局

键盘打开; 不调整 键盘打开; 调整大小 键盘打开; 调整盘

从左到右:adjustNothingadjustResize、 和adjustPan