【问题标题】:XML android:windowSoftInputMode isn't working exactly how I wantXML android:windowSoftInputMode 不能完全按照我想要的方式工作
【发布时间】:2014-03-28 19:23:18
【问题描述】:

我有一个简单的布局,如下所示:

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:fadeScrollbars="false"
        android:gravity="center_vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:lineSpacingMultiplier="1.2" />
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:descendantFocusability="beforeDescendants"
        android:focusableInTouchMode="true"
        android:orientation="vertical" >

        <EditText
            android:layout_width="match_parent"
            android:layout_height="290dp"
            android:ems="10"
            android:gravity="top" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Submit"/>
    </LinearLayout>

</RelativeLayout>

基本上,ScrollView 内有一个 TextView 表示一个问题,我希望用户在 EditText 内输入答案。

在我的AndroidManifest 中,我添加了以下内容:

<activity
    android:screenOrientation="portrait"
    android:windowSoftInputMode="???" >
</activity>

“???”是,我尝试过使用以下内容:adjustPanadjustResizeadjustPan|adjustResize

使用adjustPanadjustResize,我遇到了同样的事情:当我输入文本时,屏幕会自动向下滚动,因此键盘不会覆盖正在输入的文本。然而,这里的问题是,当我尝试突出显示键入的文本以全选、复制、剪切或粘贴时,通常出现在顶部的复制/剪切/粘贴菜单栏无法访问,因为它已被滚动出去看法。如果我尝试手动到达该菜单栏,则文本不再突出显示。

使用adjustPan|adjustResize,复制/剪切/粘贴菜单栏始终保持在可视范围内且触手可及,但如果我输入太多,输入的文本最终会被键盘遮挡。

那么我怎样才能在输入的文本永远不会被遮挡的地方继续输入,并且仍然有复制/剪切/粘贴菜单栏跟随并允许我根据需要进行偶尔的编辑?

【问题讨论】:

    标签: java android xml menu window-soft-input-mode


    【解决方案1】:

    事实证明,这个问题与android:windowsSoftInputMode 完全无关。仅当通知栏可见时,复制/剪切/粘贴栏才能完全按照预期的方式工作。删除通知栏后,复制/剪切/粘贴栏的行为不正常。

    为了避免在顶部看到明显的黑条,解决此问题的一种方法是使用:

    View decorView = getWindow().getDecorView();
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    

    所以,虽然它现在可以工作,但活动的外观并不是 100% 我希望的那样。如果有人有比这更好的解决方法,请发表评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-28
      • 1970-01-01
      相关资源
      最近更新 更多