首页 > 解决方案 > Editext 出现时隐藏在键盘后面

问题描述

当键盘出现时,我只想移动edittext。这是我的 XML 代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".chat.MultipleMediaActivity">
    <androidx.viewpager.widget.ViewPager
        android:id="@+id/multiple_media_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="0dp"
        android:layout_marginTop="0dp" />
    <include
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginTop="40dp"
        layout="@layout/multiple_media_custom_toolbar" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:background="@drawable/multimedia_edittext_bg_ca"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal"
            android:layout_marginBottom="5dp">
            <ImageView
                android:id="@+id/emoj_button"
                android:layout_width="24dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="13dp"
                android:src="@drawable/main_emoj_ca"
                android:tag="emoji" />
            <com.vanniktech.emoji.EmojiEditText
                android:id="@+id/multiple_media_text_message"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@color/AppTrasColor"
                android:hint="@string/write_message_ca"
                android:inputType="textCapSentences|textMultiLine"
                android:maxLines="4"
                android:minHeight="50dp"
                android:textColor="@color/AppFirstTextColorDark"
                android:textColorHint="@color/AppDullTextColor"
                android:textSize="@dimen/Text17"
                tools:ignore="LabelFor"
                android:layout_marginStart="10dp"/>
        </LinearLayout>
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/multiple_media_preview"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp">

        </androidx.recyclerview.widget.RecyclerView>
    </LinearLayout>
</RelativeLayout>

我在清单中尝试过的

android:windowSoftInputMode="adjustPan"  

当edittext获得焦点时,edittext保持在键盘下方,我想设置edittext的底线和键盘的顶线将是相同的。这意味着当它出现时,edittext 将始终停留在键盘上方。

标签: androidandroid-layout

解决方案


你不能。当键盘出现时,Android 有 3 种模式:

调整无 - 什么都不做。键盘将按​​原样显示在应用程序上方。这几乎从未使用过

adjustResize - 询问键盘的高度,并且应用程序适合剩余的屏幕。这将导致元素被重新排列。

adjustPan- 应用程序将滚动以使光标在屏幕上。如果这是一个多行编辑框,它保证将显示带有光标的行。它下面的其他行可能会也可能不会,这取决于光标在屏幕上的位置。

没有将整个编辑文本移动到键盘上方的模式。


推荐阅读