在AndroidManifest.xml中宣布了android:窗口软输入模式=“调整大小”
<activity
android:name="com.atfmedia.flopi.ui.MainActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize" />
下面的菜单在main_activity. xml中显示,同时也显示了查看片段,当chat_fragment. xml显示在容器中,键盘出现时,BottomNavigationView会在其上方出现。
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>
我尝试添加一个KeyboardVisibilityEvent并隐藏BottomNavigationView,但是带有输入消息的TextInputLayout出现在键盘下面。
KeyboardVisibilityEvent.setEventListener(this) { isOpen ->
if (isOpen) {
binding.bottomNavView.visibility = View.GONE
} else {
binding.bottomNavView.visibility = View.VISIBLE
}
}
我也尝试过在LinearLayout中 Package 容器和下层菜单(这样容器底部和菜单顶部就不会绑定),不幸的是,没有成功。
1.底部键盘上方的导航视图
1.键盘下方的BottomNavigationView和TextInputLayout(隐藏底部菜单时)
谁遇到过这样的行为,找到了什么解决办法?
2条答案
按热度按时间cnwbcb6i1#
尝试在chat_fragment. xml布局的根FrameLayout中添加
android:fitsSystemWindows="true"
。gt0wga4j2#
只在清单文件中使用此行
第一个月
例如:x一个月一个月x一个月二个月一个月x一个月三个月一个月x一个月四个月