I am trying to constrain the height of a MaterialButton to be the same as the height of a TextInputEditText by aligning them top to top and bottom to bottom.
However, I cannot achieve that because TextInputEditText is nested inside a TextInputLayout. With this, I can only constrain the MaterialButton with TextInputLayout which gives the following :
I would like not to remove the counter (or any helper text below the TextInputEditText).
Is there any way to constrain the MaterialButton with the nested TextInputEditText (top to top and bottom to bottom) so that they appear with the same height ?
Here is my code:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/chat_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/finish_panel">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="@+id/chat_text_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/chat_send_button"
app:endIconDrawable="@drawable/ic_clear"
app:endIconMode="clear_text"
app:helperTextEnabled="true"
app:counterMaxLength="200"
app:counterEnabled="true"
app:errorEnabled="true"
android:hint="Chat">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/chat_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textNoSuggestions"
android:maxHeight="200dp"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/chat_send_button"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="@id/chat_text_container"
app:layout_constraintBottom_toBottomOf="@id/chat_text_container"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@id/chat_text_container"
android:minWidth="0dp"
android:insetBottom="0dp"
app:icon="@drawable/ic_send"
app:iconPadding="0dp"
app:iconGravity="textStart"/>
</androidx.constraintlayout.widget.ConstraintLayout>



I see you have used
android:inputType="textNoSuggestions"for yourEditText. Which prevents you to type multiline.If you do not want to type multiline in your
EditTextthen there won't be any chance for the height of theButtonto grow. In this case you can align yourButtonwith theEditText.For that here is the XML code for your
Button.If you want to type multiline in the
EditTextthen yes, you can have yourButton's height grow with theEditTextkeeping theButtonaligned with theEditText.For that, first you need to remove
android:inputType="textNoSuggestions"fromEditText.Then use the following XML.
I have used
android:layout_marginBottom="27dp"for theButtonso that it offsets the height of the counter text. That worked perfectly fine for my two emulators with landscape and portrait orientation. If you want you can adjust that as per your need.