android 编辑在ConstraintLayout中被软键盘切成两半的文本

flvlnr44  于 2022-12-21  发布在  Android
关注(0)|答案(3)|浏览(128)

我试图创建一个聊天布局,所以我有一个循环视图,其中有一个EditText(使用圆角背景)和一个ImageButton来发送消息,但是当软键盘出现时,它覆盖了EditText和ImageButton的一小部分。
我的AndroiManifest中有android:windowSoftInputMode="adjustPan"
我试过了

  • 使用android:windowSoftInputMode="adjustResize时,它占用了所有资源,包括我的BottomNavigationView(我不希望这样)
  • app:paddingBottomSystemWindowInsets="@{true}"放在约束布局上

下面是我的布局:

<?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>

下面是我的两张图片显示的问题:

mm9b1k5b

mm9b1k5b1#

我通过执行以下操作找到了一个变通方案:
1.我在我的机器人清单中返回到adjustPan
1.在我的片段中,我补充道:

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)
}
nszi6y05

nszi6y052#

在回收视图中添加底部填充“16”。

ruarlubt

ruarlubt3#

在我的情况下,我已经实现如下,在此
1.在布局文件中添加滚动视图
1.更改应用主题

<item name="android:windowSoftInputMode">adjustResize</item>

和布局文件作为

<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/layout_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".activities.FirstActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:fillViewport="true"

        android:isScrollContainer="false"
        app:layout_constraintBottom_toTopOf="@+id/layout_bottom"
        app:layout_constraintTop_toBottomOf="@+id/layout_container">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1.7"
            android:gravity="center"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <Button
                    android:id="@+id/btn_get_started"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/ten_dp"
                    android:layout_weight="1"
                    android:background="@drawable/button_box"
                    android:backgroundTint="@color/button_color"
                    android:padding="@dimen/ten_dp"
                    android:text="Get Started" />

                <Button
                    android:id="@+id/btn_sample_tour"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/ten_dp"
                    android:layout_weight="1"
                    android:background="@drawable/button_border"
                    android:padding="@dimen/ten_dp"
                    android:text="Sample Tour"
                    android:textColor="@color/primary_color" />
            </LinearLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/ten_dp"
                android:background="@drawable/edit_text_box"
                android:hint="Enter booking code"
                android:maxLines="1"
                android:minHeight="48dp"
                android:padding="@dimen/five_dp"
                android:textColorHint="#A1887F"
                android:textSize="20sp" />
        </LinearLayout>

    </LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

仅此而已,快乐编码:)

相关问题