如何解决EditText由ConstraintLayout中的软键盘切成两半
我正在尝试创建一个聊天布局,所以我有一个带有EditText(使用圆角背景)和ImageButton来发送消息的recyclerview,但是当软键盘显示时,它会覆盖一点EditText和ImageButton的一部分。
我的android:windowSoftInputMode="adjustPan"
中有AndroiManifest
我尝试过:
- 使用
android:windowSoftInputMode="adjustResize
占用了我所有的BottomNavigationView
(我不想要) - 将
app:paddingBottomSystemWindowInsets="@{true}"
放在我的ConstraintLayout上
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_support"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
android:transcriptMode="alwaysScroll"
app:layoutManager="androidx.recyclerview.widget.linearlayoutmanager"
app:layout_constraintBottom_toTopOf="@id/et_support"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:reverseLayout="true"
tools:itemCount="3"
tools:listitem="@layout/item_support_received" />
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/et_support"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/btn_support_send"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rv_support"
/>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_support_send"
android:layout_width="50dp"
android:layout_height="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@id/et_support"
app:layout_constraintTop_toBottomOf="@id/rv_support" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
在我的2张显示问题的图像下面:
解决方法
在您的recyclerview中添加底部填充“ 16”。
,我通过以下方法找到了解决方法:
- 我已经在AndroidManifest中回到
adjustPan
- 我在片段中添加了:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
override fun onViewCreated(view: View,savedInstanceState: Bundle?) {
super.onViewCreated(view,savedInstanceState)
// Extension method I've created to hide/show the bottomNav
requireActivity().showBottomNavBar(false)
}
override fun onDestroyView() {
super.onDestroyView()
requireActivity().showBottomNavBar(true)
activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。