Android EditText不使用多行扩展
我在聊天版面中有EditText,当用户键入多行时,该版面应该会展开。 我使用了android:inputType=“textMultiLine | textNoSuggestions”,但它不起作用。 我尝试使用android:singleLine=“false”和Android EditText不使用多行扩展,android,kotlin,android-edittext,multiline,android-inputtype,Android,Kotlin,Android Edittext,Multiline,Android Inputtype,我在聊天版面中有EditText,当用户键入多行时,该版面应该会展开。 我使用了android:inputType=“textMultiLine | textNoSuggestions”,但它不起作用。 我尝试使用android:singleLine=“false”和 write_et.setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE or InputType.TYPE_TEXT_FLAG_
write_et.setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS)
write_et.setSingleLine(false)
但它仍然不起作用。
这是我的代码:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@android:color/white"
android:layout_height="match_parent"
tools:context="com.improve.myproject.fragments.ChatFragment">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toTopOf="@id/send_btn"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"/>
<ImageView
android:id="@+id/send_btn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="16dp"
android:padding="8dp"
android:background="@drawable/send_shape"
android:src="@drawable/ic_arrow_back_white_24dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:contentDescription="to info"
android:tooltipText="@string/take_out_frustration"/>
<EditText
android:id="@+id/write_et"
android:inputType="textMultiLine|textNoSuggestions"
android:singleLine="false"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@id/send_btn"
android:background="@drawable/text_sender_bg"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:padding="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:textColor="@color/colorPrimary"
android:textSize="20sp"
android:textColorHint="#7EB2F5"
android:hint="@string/type_here_chat"
android:fontFamily="@font/comixno2_medium"/>
</androidx.constraintlayout.widget.ConstraintLayout>
编辑:
正如@Md.Asaduzzaman所显示的,问题不在xml中
对于这个xml,我有一个带有firebase realtime listener的片段,当您单击send按钮时,为send按钮设置ClickListener,将消息上载到firebase realtime,并隐藏键盘功能
有人知道是什么导致了这种行为吗
发现的问题:
问题是我在清单中写了windowSoftInputMode=“adjustPan”
因此,我的解决方案是将其更改为调整大小并自行处理其他布局的移动。我只尝试了您的xml代码,如下所示:
<EditText
android:id="@+id/write_et"
android:inputType="textMultiLine|textNoSuggestions"
android:singleLine="false"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@id/send_btn"
android:background="#d3d3d3"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:padding="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:textColor="@color/colorPrimary"
android:textSize="20sp"
android:textColorHint="#7EB2F5"
android:hint="type_here_chat"/>
输出是这样的
N.B:为了用图片解释,我添加了这个作为答案你可以试着玩
android:lines
,android:minLines
和android:maxLines
,具体取决于你的具体要求。谢谢,但我已经试过了,仍然不工作。问题是字段最初显示为一行,而您希望它最初显示为多行?或者字段最初显示为多行,并且希望随着用户在其中键入字符而变大?问题是editText不会展开,它应该以一行开始,如果有,则展开multilines@YiShai这是你的要求还是别的什么?这是它应该做的,但对我来说不是,我在不同的设备上运行我的应用程序,但仍然存在相同的问题。因此,正如我们所看到的,问题不在xml中,而是其他东西。你知道这是什么原因吗?你有没有在删除程序应用代码后尝试过,或者创建了一个示例应用程序,然后尝试删除一些代码,但是我有一个大的应用程序,所以我没有尝试所有的方法