I have EditText in a chat layout, that is supposed to expand when the user is typing more than one line. I used android:inputType="textMultiLine|textNoSuggestions"
but it's not working. I tried to use android:singleLine="false"
and
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)
but it's still not working. This is my code:
<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>
EDIT: As @Md. Asaduzzaman showed the problem is not in the xml.
for this xml I have a fragment with firebase realtime listener, setOnClickListener for the send button uploading a message to firebase realtime, and hide keyboard function, when you click on the send button.
Do anyone know what could make this behavior happen?
PROBLEM FOUND: The problem was that in my Manifest I wrote windowSoftInputMode="adjustPan"
so my solution was to change it to adjustResize and handle the movement of other layouts by myself.
I have tried your xml code only like below:
<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"/>
And the output something like that
NB: To explain with image I have added this as Answer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.