In AndroidManifest.xml announced android:windowSoftInputMode="adjustResize"
<activity
android:name="com.atfmedia.flopi.ui.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize" />
The lower menu is announced in main_activity.xml , as well as viewing fragments. When the chat_fragment.xml is displayed in the container and the keyboard appears, the BottomNavigationView rises above it.
main_activity.xml
<?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:id="@+id/activityRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/bottomNavView"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/tab_graph"
tools:layout="@layout/swipes_fragment" />
<com.atfmedia.flopi.view.ProgressBackground
android:id="@+id/registrationProgress"
android:layout_marginTop="40dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="3dp" />
<ImageButton
android:id="@+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_left"
android:layout_marginTop="20dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintTop_toTopOf="parent"
android:padding="10dp"
android:layout_marginStart="5dp"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="ContentDescription" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
app:labelVisibilityMode="unlabeled"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/main_bottom_menu" />
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progressIndicator"
android:layout_width="match_parent"
android:indeterminate="true"
android:visibility="gone"
tools:visibility="visible"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/nav_host_fragment" />
</androidx.constraintlayout.widget.ConstraintLayout>
chat_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/chatContentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/messageRecycler"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="16dp"
android:layout_weight="1"
android:overScrollMode="never" />
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="16dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="41dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_weight="1">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/messageInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
app:boxCornerRadiusBottomEnd="20dp"
app:boxCornerRadiusBottomStart="20dp"
app:boxCornerRadiusTopEnd="20dp"
app:boxCornerRadiusTopStart="20dp"
app:boxStrokeWidth="0dp"
app:boxStrokeWidthFocused="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/messageEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="0dp"
android:paddingBottom="0dp" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/addPhotoButton"
android:layout_width="0dp"
android:layout_height="0dp"
android:paddingEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="wrap"
app:srcCompat="@drawable/ic_add_photo" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/photoBadge"
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_margin="12dp"
app:layout_constraintEnd_toEndOf="@id/addPhotoButton"
app:layout_constraintTop_toTopOf="@id/addPhotoButton"
app:srcCompat="@drawable/ic_badge_bg" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/sendImageView"
android:layout_width="41dp"
android:layout_height="41dp"
android:layout_marginEnd="16dp"
android:background="?selectableItemBackgroundBorderless"
android:clickable="false"
android:alpha="0.75"
android:focusable="true"
android:src="@drawable/ic_profile_send_msg" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
</FrameLayout>
I tried to add a KeyboardVisibilityEvent and hide the BottomNavigationView, but then TextInputLayout with the entered message goes under the keyboard.
KeyboardVisibilityEvent.setEventListener(this) { isOpen ->
if (isOpen) {
binding.bottomNavView.visibility = View.GONE
} else {
binding.bottomNavView.visibility = View.VISIBLE
}
}
I also tried to wrap the container and the lower menu in LinearLayout (so that there was no binding of the bottom of the container to the top of the menu), unfortunately, unsuccessfully.
- BottomNavigationView above the keyboard
- BottomNavigationView and TextInputLayout under keyboard (when hiding the bottom menu)
Who has encountered such behavior and what solutions have found ?
2
Answers
try to add
android:fitsSystemWindows="true"
in the root FrameLayout of the chat_fragment.xml layout.
just use this line at the manifest file
android:windowSoftInputMode="adjustPan"
for example: