android - 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 将始终停留在键盘上方。
解决方案
你不能。当键盘出现时,Android 有 3 种模式:
调整无 - 什么都不做。键盘将按原样显示在应用程序上方。这几乎从未使用过
adjustResize - 询问键盘的高度,并且应用程序适合剩余的屏幕。这将导致元素被重新排列。
adjustPan- 应用程序将滚动以使光标在屏幕上。如果这是一个多行编辑框,它保证将显示带有光标的行。它下面的其他行可能会也可能不会,这取决于光标在屏幕上的位置。
没有将整个编辑文本移动到键盘上方的模式。
推荐阅读
- python - 当它在Python中中断时如何列出while循环中的所有值?
- python - Python:Ctypes如何检查内存管理
- android - 在 Cordova 上将 AngularJS webapp 构建到 android 时出现问题
- ansible - 如何在 Gitlab 和 Ansible 之间设置握手
- python - 我可以将自定义令牌规则应用于由 spaCy 中的前缀拆分的令牌吗?
- javascript - Javascript简化条件
- python - 来自包含 NaN 值的数据的 Pandas 数据框列
- java - JButton 不产生输出 - 石头剪刀布游戏(GUI、Java)
- mysql - MySQL 上的全文搜索:无法在连字符/破折号后按单词搜索
- wso2 - WSO2 通过 Web 服务进行身份验证