聚焦EditText和屏幕旋转后,Android UI的“浮动操作按钮”被软键盘覆盖了

问题描述

问题与标题相同。 我在屏幕右下角有一个浮动操作按钮。当单击某些editText字段时,此按钮将按照屏幕截图很好地浮动到屏幕键盘的顶部:

enter image description here

如果我将焦点设置在editText视图上,然后旋转屏幕,问题就会开始。从那以后,每当我单击editText字段时,键盘都会出现,但浮动按钮却没有,因此键盘会掩盖它。

赞:

enter image description here

发生这种情况之后,无论我在框架之间移动还是进行一些活动都没有关系。问题依然存在,无论我有哪些editText字段和浮动按钮,该行为都会在整个应用程序中出现,它不会随键盘浮动。它只是被键盘遮盖了。只有在我完全关闭应用程序并重新启动后,一切恢复正常。

现在,关于Android开发,我仍然是新手,所以我不确定我可以/应该提供更多的信息。我正在使用Android Xiaomi P30 pro进行测试(如果有区别)。

android设置

compileSdkVersion 29
buildToolsversion "30.0.0"

defaultConfig {
    applicationId "ee.taltech.mobile.contacts"
    minSdkVersion 26
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"

按钮和editTxt字段的资源

<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"
    android:padding="16dp"
    tools:context=".fragments.AddPersonFragment">

    <EditText
        android:id="@+id/addContactValue_edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:hint="First Name"
        android:inputType="textPersonName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/addLastName_edit"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="16dp"

        android:ems="10"
        android:hint="Last Name"
        android:inputType="textPersonName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/addContactValue_edit" />


    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/add_person_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="24dp"
        android:layout_marginBottom="24dp"
        android:clickable="true"
        android:focusable="true"
        android:src="@drawable/ic_check"
        android:tint="@android:color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)