Reputation: 2544
I am trying to wrap the text in EditText but its not working. I have tried many solutions from stackoverflow but nothing is working for me.
Here is the EditText code within card view layout.
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_small"
android:layout_weight="1"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="18dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_xmlarge"
android:orientation="horizontal"
android:paddingLeft="@dimen/spacing_small"
android:paddingRight="@dimen/spacing_small">
<ImageView
android:layout_width="@dimen/spacing_xmlarge"
android:layout_height="@dimen/spacing_xmlarge"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="@dimen/spacing_middle"
android:tint="#00897B"
app:srcCompat="@drawable/ic_sentiment_satisfied" />
<EditText
android:id="@+id/edittext_chat_log"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:gravity="top|left"
android:hint="Write a message..."
android:imeOptions="actionSearch"
android:inputType="textMultiLine|textCapSentences"
android:lines="5"
android:maxLines="10"
android:minLines="1"
android:padding="@dimen/spacing_middle"
android:scrollbars="none" />
<ImageView
android:id="@+id/photoPickerButton"
android:layout_width="@dimen/spacing_xmlarge"
android:layout_height="@dimen/spacing_xmlarge"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="@dimen/spacing_middle"
android:tint="#00897B"
app:srcCompat="@drawable/ic_photo_camera" />
</LinearLayout>
</androidx.cardview.widget.CardView>
Here is the complete xml file code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E9E4"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#075E54"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/lyt_back"
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/spacing_medium"
android:paddingRight="@dimen/spacing_medium">
<ImageButton
android:id="@+id/chat_back_press"
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
app:srcCompat="@drawable/ic_arrow_back" />
<View
android:layout_width="@dimen/spacing_medium"
android:layout_height="0dp" />
<com.mikhaellopez.circularimageview.CircularImageView
android:id="@+id/image"
android:layout_width="36dp"
android:layout_height="36dp"
android:src="@drawable/photo_male_8"
app:civ_border="true"
app:civ_border_color="#075E54"
app:civ_border_width="0dp"
app:civ_shadow="true"
app:civ_shadow_radius="0" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/spacing_small"
android:paddingRight="@dimen/spacing_small">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Roberts"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@android:color/white"
app:fontFamily="sans-serif-medium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Online"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="@color/grey_10" />
</LinearLayout>
<androidx.appcompat.widget.Toolbar
android:id="@+id/chat_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!-- <android.support.v7.widget.RecyclerView-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview_chat_log"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/spacing_medium"
android:paddingBottom="@dimen/spacing_medium"
android:scrollbars="vertical"
android:scrollingCache="true"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentTop="true"
android:background="@drawable/bg_gradient_soft"
android:rotation="180" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/spacing_medium">
<!-- <android.support.v7.widget.CardView-->
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_small"
android:layout_weight="1"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="18dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/spacing_xmlarge"
android:orientation="horizontal"
android:paddingLeft="@dimen/spacing_small"
android:paddingRight="@dimen/spacing_small">
<ImageView
android:layout_width="@dimen/spacing_xmlarge"
android:layout_height="@dimen/spacing_xmlarge"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="@dimen/spacing_middle"
android:tint="#00897B"
app:srcCompat="@drawable/ic_sentiment_satisfied" />
<EditText
android:id="@+id/edittext_chat_log"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:gravity="top|left"
android:hint="Write a message..."
android:imeOptions="actionSearch"
android:inputType="textMultiLine|textCapSentences"
android:lines="5"
android:maxLines="10"
android:minLines="1"
android:padding="@dimen/spacing_middle"
android:scrollbars="none" />
<ImageView
android:id="@+id/photoPickerButton"
android:layout_width="@dimen/spacing_xmlarge"
android:layout_height="@dimen/spacing_xmlarge"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="@dimen/spacing_middle"
android:tint="#00897B"
app:srcCompat="@drawable/ic_photo_camera" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<!-- <android.support.design.widget.FloatingActionButton-->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/send_button_chat_log"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_small"
android:clickable="true"
android:gravity="center"
android:tint="@android:color/white"
app:backgroundTint="#00897B"
app:elevation="1dp"
app:fabSize="mini"
app:srcCompat="@drawable/ic_mic"
app:useCompatPadding="false" />
</LinearLayout>
Upvotes: 0
Views: 1054
Reputation: 71
Your layout design with several problems. The critical one is that parent limited the view. Height of EditText is set as match_parent. It will match your linear layout. The fast way to resolve your problem just modify following statements.
The content layout should be wrap too.
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_small"
android:layout_weight="1"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="18dp"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" <!--here-->
Your EditText should be wrap too.
<EditText
android:id="@+id/edittext_chat_log"
android:layout_width="0dp"
android:layout_height="wrap_content" <!--here-->
android:layout_weight="1"
If you don't want to limit the height, please remove android:lines="5"
If you want to limit the lines to 10, just keep android:lines="10", not need to keep android:maxLines="10" and android:minLines="1"
Then problem is fixed.
Upvotes: 3
Reputation: 402
In your EditText
, try setting singleLine=false. Since a value is specified for inputType.
Reference: https://developer.android.com/reference/android/widget/TextView.html#attr_android:singleLine
android:singleLine
Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key. The default value is false (multi-line wrapped text mode) for non-editable text, but if you specify any value for inputType, the default is true (single-line input field mode).
May be a boolean value, such as "true" or "false".
<EditText
android:id="@+id/edittext_chat_log"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/transparent"
android:gravity="top|left"
android:hint="Write a message..."
android:imeOptions="actionSearch"
android:inputType="textMultiLine|textCapSentences"
android:lines="5"
android:maxLines="10"
android:minLines="1"
android:padding="@dimen/spacing_middle"
android:scrollbars="none" />```
Upvotes: 0