【问题标题】:How to stop a soft keyboard to overlap on my button如何阻止软键盘重叠在我的按钮上
【发布时间】:2020-01-03 06:33:58
【问题描述】:
<Button android:layout_width="match_parent"
                android:background="@drawable/rectangle_app_btn"
                android:layout_height="60dp"
                android:text="@string/next"
                android:textColor="@color/white"
                android:fontFamily="@font/montserrat_medium"
                android:textSize="18sp"
                android:textAllCaps="false"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                android:id="@+id/login_nxt_btn"
        />

对不起,我是新来的。我有这个问题,每当我在 EditText 上打开我的软键盘时,软键盘就会在这个按钮上重叠。但几秒钟后,该按钮将显示在软键盘上方。

每当我打开我的软键盘时,我想让这个按钮位于软键盘的上方。我已经尝试了互联网上所说的一切。喜欢android:windowSoftInputMode="stateVisible|adjustPan",但仍然没有运气。我也试过把ScrollView希望有人能帮助我。

【问题讨论】:

  • 你试过android:windowSoftInputMode="adjustResize"吗?
  • 尝试调整调整大小。如果您的按钮位于底部并且您正在使用滚动视图。使您的滚动视图在您的按钮上方。这将解决您的问题。
  • 大家好,是的,我已经尝试过 adjustResize 并且我已经尝试过 layout_above 我的底部按钮
  • 你能把xml文件的完整代码贴出来让我帮你
  • @Arti here 先生 pastebin.com/2QdcZ2cd

标签: android xml kotlin


【解决方案1】:

您可以在 Activity 标记内的 AndroidMainfest.xml 文件中简单地将 Activity 的 windowSoftInputModeflag 切换为 adjustPan。

<activity
   ...
   android:windowSoftInputMode="adjustPan"> 
</activity>

【讨论】:

    【解决方案2】:

    尝试在 XML 中使用下一个变体:

    <activity
       ...
       android:windowSoftInputMode="adjustResize"> 
    </activity>
    

    【讨论】:

      【解决方案3】:

      在您的 xml 中使用相对布局,以下属性将起作用。在您的清单活动标签中添加此属性。

      android:windowSoftInputMode="adjustResize"
      

      【讨论】:

      • 我正在使用带有线性布局子的约束布局,我已经在清单上尝试过,先生仍然没有运气
      【解决方案4】:

      试试下面的代码,它对我有用,

      <?xml version="1.0" encoding="utf-8"?>
      <androidx.constraintlayout.widget.ConstraintLayout 
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".MainActivity">
      
          <LinearLayout
              android:id="@+id/linearLayout"
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:orientation="vertical"
              app:layout_constraintBottom_toTopOf="@+id/buttomButtom"
              app:layout_constraintLeft_toLeftOf="parent"
              app:layout_constraintRight_toRightOf="parent"
              app:layout_constraintTop_toTopOf="parent">
      
              <EditText
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:textColor="@color/colorPrimary"
                  android:hint="Hello World!" />
          </LinearLayout>
      
          <Button
              android:id="@+id/buttomButtom"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:layout_constraintBottom_toBottomOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              android:text="Bottom Button"
              app:layout_constraintStart_toStartOf="parent" />
      </androidx.constraintlayout.widget.ConstraintLayout>
      

      你还必须在清单中提到输入模式

      android:windowSoftInputMode="adjustResize|stateVisible"
      

      这是对我有用的视频

      【讨论】:

      • 先生,我正在尝试。
      • 感谢您抽出宝贵时间并愿意提供帮助,但在我的情况下它不起作用。我真的很感激这位先生。
      • 分享完整版面,便于理解,解决您的问题
      • 但这就是我想要的,先生
      • pastebin.com/2QdcZ2cd 这是整个布局先生@akshay
      【解决方案5】:

      尝试做这样的事情

      <androidx.constraintlayout.widget.ConstraintLayout
         <NestedScrollView
          --your other view
         </NestedScrollView>
         <Button />
      </androidx.constraintlayout.widget.ConstraintLayout>
      

      【讨论】:

        猜你喜欢
        • 2023-03-30
        • 2013-01-24
        • 2011-12-22
        • 1970-01-01
        • 2013-02-25
        • 2019-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多