android - Toolbar moves up when keyboard appears in fragment android
问题描述
I'm currently dealing with 1 problem in my Android App. I have a Fragment with a toolbar and with an EditText placed at the bottom. The first problem that I found was that when my keyboard appears the toolbar moves up, I found a solution for this adding this line of code in my Manifest.xml in the parent activity:
android:windowSoftInputMode="adjustPan|adjustResize"
it works well, with this code my toolbar doesn't move up, but my EditText stays hidden by the keyboard and I'm not able to see what I'm typing.
This is my chat Fragment view
When my keyboard appears, toolbar moves up and EditText is overlaping with the keyboard
After I added adjustResize and adjustPan, my toolbar doesn't move up when the keyboard appears, but my EditText stays hidden
I hope you can help me, thanks!
My layout:
<?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:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/materialToolbar"
android:layout_width="0dp"
android:layout_height="60dp"
android:elevation="5dp"
android:background="@android:color/white"
app:layout_constraintBottom_toTopOf="@id/rclv_chats"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/btnback"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/icon_back"
android:layout_marginLeft="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
</com.google.android.material.imageview.ShapeableImageView>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/img"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/foto_guy"
app:riv_corner_radius="15dp"
android:layout_marginRight="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent">
</de.hdodenhof.circleimageview.CircleImageView>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/txt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textColor="#000000"
android:layout_marginLeft="15dp"
android:fontFamily="@font/sf_regular"
app:layout_constraintStart_toEndOf="@id/img"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
</com.google.android.material.textview.MaterialTextView>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.MaterialToolbar>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rclv_chats"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/materialToolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/view">
</androidx.recyclerview.widget.RecyclerView>
<View
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="60dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/rclv_chats"
android:background="#D9D9D9">
</View>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/white"
android:layout_marginRight="15dp"
android:src="@drawable/icon_send"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@id/view"
app:layout_constraintTop_toTopOf="@id/view">
</com.google.android.material.floatingactionbutton.FloatingActionButton>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_msj"
android:layout_width="0dp"
android:layout_height="40dp"
android:background="@drawable/design_chat_inputmessage"
android:hint="Escribe un mensaje"
android:textColor="@android:color/black"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="14sp"
android:textColorHint="@android:color/darker_gray"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="@id/view"
app:layout_constraintTop_toTopOf="@id/view"
app:layout_constraintEnd_toStartOf="@id/fab_send">
</com.google.android.material.textfield.TextInputEditText>
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
推荐阅读
- material-ui - 来自 '@material-ui /styles' 的 {withStyles} 断点
- c# - 在 Linq 之间添加 if 语句
- java - 微服务 - 如何使用授权服务器和资源服务器对注册流程进行建模?
- c++ - 如何更改此插入函数以使用字符串在链表中工作?
- java - Android videoview - 沉浸式 - 重叠控制器
- c# - X509Certificate2 的 RawData 与 Export(X509ContentType.Cert) 有什么区别?
- webrtc - WebRtc 信令服务器可以在没有额外 STUN 服务器的情况下为客户端找到 ICE 候选者吗
- java - 无法自定义flowers_tf_lite.ipynb colab 中的_URL
- mysql - 利息查询日期减去总付款日期
- excel - 为什么我的使用 VBA 抓取文本的代码仅在调试中有效