我几乎尝试了所有软键盘在弹出时覆盖部分 View 的解决方案,经过进一步调查,我发现覆盖布局的不是键盘,而是建议条。 但从键盘设置中禁用建议条似乎是唯一的解决方案。
我尝试过一些技巧,这些技巧可以在键盘弹出时在运行时添加填充,但似乎都不起作用。
This screenshot will explain it better
下面的代码 fragment 来 self 的 BottomSheetDialog:
<?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"
android:id="@+id/design_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/feedback_text"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/recognition_text_box_border_drawable"
android:gravity="start"
android:hint="@string/manager_recognition_edit_text_hint"
android:importantForAutofill="no"
android:inputType="textMultiLine|textCapSentences"
android:maxLength="200"
android:maxLines="24"
android:overScrollMode="always"
android:padding="8dp"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/award_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="@id/feedback_text"
app:layout_constraintEnd_toEndOf="@id/feedback_text"
app:srcCompat="@drawable/trophy_golden" />
<include
android:id="@+id/award_badge_item"
layout="@layout/award_badge_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="@id/feedback_text"
app:layout_constraintStart_toStartOf="@id/feedback_text" />
<LinearLayout
android:id="@+id/buttons_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:orientation="horizontal"
android:weightSum="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/feedback_text">
<Button
android:id="@+id/cancel_recognition"
style="@style/Widget.AppCompat.Button"
android:layout_width="0dp"
android:layout_height="@dimen/medium_button_height"
android:layout_margin="4dp"
android:layout_weight="1"
android:text="@android:string/cancel" />
<Button
android:id="@+id/send_recognition"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="0dp"
android:layout_height="@dimen/medium_button_height"
android:layout_margin="4dp"
android:layout_weight="2"
android:text="@string/send_recognition" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
最佳答案
将此行添加到要打开键盘的 list Activity 标记中
android:windowSoftInputMode="stateHidden|adjustResize"
关于java - 软键盘的建议条隐藏了部分布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58121197/