I have a problem. TextInputLayout has margin or padding with respect to the line.
I need the line to be the full width.
Docs:
https://material.io/develop/android/components/text-input-layout/
Code:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/inputLayoutEmail"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingBottom="0dp"
app:boxBackgroundColor="#color/colorBgDisableButton"
app:boxCornerRadiusTopEnd="10dp"
app:boxCornerRadiusTopStart="10dp"
android:hint="#string/text_signup_email"
android:textColorHint="#color/colorTextInput"
android:focusable="false"
android:clickable="false"
app:errorEnabled="true"
app:errorTextAppearance="#style/ErrorTextAppearance"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/inputTextEmail"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorLineInput"
android:fontFamily="#font/century_gothic"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:lines="1"
android:maxLines="1"
android:paddingStart="22dp"
android:paddingBottom="20dp"
android:textColor="#color/colorTextInput"
android:textSize="14sp"
android:enabled="false"
android:focusable="false"
android:clickable="false"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
/>
</com.google.android.material.textfield.TextInputLayout>
match_parent both fields and all will go well
Related
I'm having an issue where my TextInputLayout label is being overlapped by the input within an AppCompatAutoCompleteTextView. My apologies if this has been answered before. Here is my code snippet:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/commission_form_category_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="#+id/commission_form_category_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/commission_form_category_label_text"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:text="Hello"
android:singleLine="true"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
Here is what it looks like:
overlapping text
Change androidx.appcompat.widget.AppCompatAutoCompleteTextView to com.google.android.material.textfield.MaterialAutoCompleteTextView and add style to TextInputLayout
here is how it looks
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/commission_form_category_container"
android:layout_width="match_parent"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:hint="Hint"
android:layout_height="wrap_content">
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="#+id/commission_form_category_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello"
android:singleLine="true"
android:textSize="16sp" />
</com.google.android.material.textfield.TextInputLayout>
Try this-
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Example">
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
style="#style/Widget.MaterialComponents.AutoCompleteTextView.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello" />
</com.google.android.material.textfield.TextInputLayout>
Instead of paddingVertical and paddingHorizontal you can specify padding via
paddingTop
paddingStart
paddingEnd
paddingBottom
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/commission_form_category_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="#+id/commission_form_category_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/commission_form_category_label_text"
android:paddingTop="24dp"
android:paddingBottom="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:text="Hello"
android:singleLine="true"
android:textSize="16sp" /></com.google.android.material.textfield.TextInputLayout>
How to set hint of TextInputEditText on top of view.
I have the following edit text that user will type description of the product, but hint is on center of view.
Here is the XML code.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/interestDescriptionView"
style="#style/TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:maxLines="5"
app:layout_constraintBottom_toTopOf="#+id/tagsView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleView"
app:layout_constraintVertical_chainStyle="packed">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/interestDescriptionEditTextView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:textAlignment="viewStart"
android:hint="Descrição *"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
android:importantForAutofill="no" />
</com.google.android.material.textfield.TextInputLayout>
You can set android:minLines to 2 or greater .. this will make it work
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/interestDescriptionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Descrição *"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textview"
app:layout_constraintVertical_chainStyle="packed">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/interestDescriptionEditTextView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:gravity="top"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:inputType="textMultiLine|textCapSentences"
android:maxLines="5"
android:minLines="2"
android:textAlignment="viewStart" />
</com.google.android.material.textfield.TextInputLayout>
Also you can check other workarounds from here
I have added TextInputLayout with TextInputEditText. But when I start typing the bottom border is automatically display.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/input_layout_etText"
android:layout_width="match_parent"
android:background="#null"
app:boxBackgroundMode="none"
app:boxStrokeWidth="0dp"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etText"
android:layout_width="match_parent"
android:layout_height="#dimen/_35sdp"
android:layout_gravity="center"
android:imeOptions="actionNext"
android:background="#null"
android:maxLines="1"
android:paddingLeft="#dimen/_5sdp"
android:paddingRight="#dimen/_5sdp"
android:textColor="#color/colorBlack"
android:textSize="#dimen/_11sdp" />
</com.google.android.material.textfield.TextInputLayout>
Use the below code to remove the line.
<com.google.android.material.textfield.TextInputLayout
app:boxStrokeWidth="0dp"
app:boxStrokeWidthFocused="0dp"
...>
I have an inputText field(TextInputLayout's EditText) of fixed height.
I want to align hint text to top left of the view.
Problem: hint text is always displayed at center_verticle but I want to display it at top left corner.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/aboutWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="About Sponsor">
<EditText
android:id="#+id/et_about_sponsor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="250dp"
android:textAlignment="viewStart"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/font_medium" />
</com.google.android.material.textfield.TextInputLayout>
As per this github issue you need to set android:minLines to at least 2 along with android:gravity="top".
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/txtInput"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Hint">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/et_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
**android:minLines="2"**
/>
</com.google.android.material.textfield.TextInputLayout>
You can use:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="About Sponsor">
<com.google.android.material.textfield.TextInputEditText
android:minHeight="250dp"
android:textAlignment="viewStart"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
.../>
</com.google.android.material.textfield.TextInputLayout>
Try to add style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style to the TextInputLayout
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/aboutWrapper"
android:layout_width="match_parent"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_height="wrap_content"
android:hint="About Sponsor">
<EditText
android:id="#+id/et_about_sponsor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="250dp"
android:textAlignment="viewStart"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/font_medium" />
</com.google.android.material.textfield.TextInputLayout>
You can use
<EditText
android:id="#+id/editTextTextPersonName5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:hint="Message"
android:gravity="left|top"
android:inputType="textAutoComplete"
android:textAlignment="textStart" />
Here gravity attribute will help in aligning the text to whichever you want.
You can Refer Here
I'm using TextInputEditTexts as text entry, and when I select them, the hint moves up as it should, but is covered by the outline of the box. Does anyone know why that would be happening?
Photo:
Code:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/title_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/grey"
android:theme="#style/OutlinedEditText"
app:boxStrokeColor="#color/blue"
app:hintTextColor="#color/blue"
app:layout_constraintTop_toBottomOf="#id/cover_art">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:hint="#string/title"
android:inputType="textCapWords" />
</com.google.android.material.textfield.TextInputLayout>
Remove in the TextInputEditText
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
In this way you are adding a margin between the main container (TextInputLayout) and the EditText
Use:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/title_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:hint="...."
...
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="textCapWords" />
</com.google.android.material.textfield.TextInputLayout>
You are placing android:hint="#string/title" attribute in com.google.android.material.textfield.TextInputEditText.
The android:hint="#string/title" should be placed in com.google.android.material.textfield.TextInputLayout
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/title_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/grey"
android:theme="#style/OutlinedEditText"
app:boxStrokeColor="#color/blue"
app:hintTextColor="#color/blue"
android:hint="#string/title"
app:layout_constraintTop_toBottomOf="#id/cover_art">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:inputType="textCapWords" />
</com.google.android.material.textfield.TextInputLayout>