【问题标题】:windowSoftInputMode="adjustResize|stateHidden" Keyboard OverLays Editexts ErrorwindowSoftInputMode="adjustResize|stateHidden" 键盘覆盖 Editexts 错误
【发布时间】:2019-09-18 17:37:15
【问题描述】:

尝试使用window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
在活动中。还尝试使用 ADJUST_RESIZE 参数它不起作用。

以下代码是我的活动清单

<activity android:name=".auth.AuthActivity"
          android:theme="@style/NoActionBarTheme"
          android:windowSoftInputMode="adjustResize|stateHidden">
</activity>

这是我的模拟器截图


尝试了大多数解决方案。可能是我错过了正确的解决方案

【问题讨论】:

    标签: android android-edittext window-soft-input-mode


    【解决方案1】:

    当您在editBox 上设置错误时,您可以通过编程方式隐藏键盘

     public void hideKeyboard() {
            View view = this.getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager)
                        getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }
            }
        }
    

    【讨论】:

    • 这不起作用,因为我需要在用户输入editText中的文本时显示错误
    • 是的,我知道,但我需要的是不同的。需要向用户显示错误,直到它消失
    【解决方案2】:

    layout 中使用ScrollView,并将所有字段放入ScrollView,以便它们可以垂直移动。然后当键盘弹出时,字段可以轻松移动,并且不会隐藏任何内容。

    【讨论】:

    • 我已经在使用一个nestedScollView 来包装我的约束布局
    • 这些字段是 NestedScrollView 的直接子字段吗?
    • 你能按照 NestedScrollView->ConstraintLayout->AllFields 的方式安排布局
    • 这可能最适合滚动视图
    • 是的,就像这样 NestedScrollView->ConstraintLayout->AllFields
    【解决方案3】:

    使用它的工作代码

    将此代码放在创建中

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

    把这个放在清单上

      android:windowSoftInputMode="adjustResize"
    

    【讨论】:

      【解决方案4】:

      这样试试

      <ScrollView
              android:layout_width="match_parent"
              android:layout_height="match_parent" >
      
      
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical">
      
      
              <EditText
                  android:id="@+id/edittext1"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:hint="player1"
                  android:layout_marginTop="10dp"/>
      
              <EditText
                  android:id="@+id/edittext2"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="10dp"
                  android:hint="player2"/>
      
              <EditText
                  android:id="@+id/edittext3"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="10dp"
                  android:hint="player3"/>
      
      
              <EditText
                  android:id="@+id/edittext4"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:hint="player4"
                  android:layout_marginTop="10dp" />
          </LinearLayout>
      
      </ScrollView>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多