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>
Related
I need to set drawableLeft aligned horizontally with the hint and moved them both closer to the bottom of the TextInputEditText. I have tried a lot of attributes but to no avail! Could I be missing something here?
Drawable seems to be where I want it but I need the hint to come below to align with drawable.
<?xml version="1.0" encoding="UTF-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_login_dialog_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello!"
android:textAlignment="center"
android:textColor="#color/teal_700"
android:textSize="32sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/til_email_user_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
app:boxBackgroundColor="#android:color/transparent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_login_dialog_title">
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/ti_et_email_user_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_baseline_email_24"
android:gravity="bottom"
android:hint="#string/field_hint_email"
android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/til_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
app:boxBackgroundColor="#android:color/transparent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/til_email_user_id">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/ti_et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_baseline_lock_24"
android:gravity="bottom"
android:hint="#string/field_hint_password" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Just Remove
android:drawableLeft="Drawable"
from TextInputEditText and add
app:startIconDrawable="Drawable"
into the TextInputLayout
or you can replace your TextInputLayout from below code
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/til_email_user_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/share_card"
android:background="#android:color/transparent"
app:boxBackgroundColor="#android:color/transparent"
app:startIconDrawable="#drawable/icn_sort_by"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_login_dialog_title">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/ti_et_email_user_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
Make your drawable height and weight 24dp. Then add these to your TextInputEditText. This is not an official answer btw. I do it like this every time.
android:paddingVertical="10dp"
android:drawablePadding="10dp"
android:gravity="center_vertical"
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
This is the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Spinner
android:id="#+id/spinnerFreq"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/start_freq_text"
android:textColorHint="#android:color/black">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editTextStartFreq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/start_freq_edit_text"
android:textColor="#android:color/black" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/end_freq_text"
android:textColorHint="#android:color/black">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editTextEndFreq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/end_freq_edit_text"
android:textColor="#android:color/black" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/length_seconds_text"
android:textColorHint="#android:color/black">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editTextLength"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/length_seconds_edit_text"
android:textColor="#android:color/black" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/min_freq_text"
android:textColorHint="#android:color/black">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editTextMinFreq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/min_freq_edit_text"
android:textColor="#android:color/black" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/max_freq_text"
android:textColorHint="#android:color/black">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/editTextMaxFreq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/max_freq_edit_text"
android:textColor="#android:color/black" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
I tried using a ConstraintLayout before the LinearLayout and the top TextInputLayout was rendered correctly. The ones below it are exactly the same, so I am not sure why they aren't working.
It's an issue with the TextInputLayout hint not moving up until the TextInputLayout gets tapped. Is there a way to get it to stay up top?
Is there a attribute I need to set or a certain way I need to lay them out? The documentation on the Material io page doesn't have a layout example on the text field page. https://material.io/develop/android/components/text-fields
Remove the hint from TextInputEditText and use the app:placeholderText in the TextInputLayout:
<com.google.android.material.textfield.TextInputLayout
android:hint="Label"
app:placeholderText="Placeholder Text"
Note: it requires at least the version 1.2.0-alpha03.
I want to show the label "Km" with a white background with the same height as that of the edit text field.
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayoutInputDist"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="wrap_content"
android:layout_height="42dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/inputDist"
android:layout_width="80dp"
android:layout_height="match_parent"
android:background="#drawable/bg_left_corner_shape"
android:backgroundTint="#android:color/white"
android:fontFamily="#font/roboto_regular"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxEms="4"
android:padding="4dp"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/label_km"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:background="#drawable/bg_right_corner_shape"
android:backgroundTint="#android:color/white"
android:fontFamily="#font/roboto_regular"
android:gravity="center_vertical"
android:text="#string/km"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textInputLayoutInputDist"
app:layout_constraintTop_toTopOf="#+id/textInputLayoutInputDist" />
</androidx.constraintlayout.widget.ConstraintLayout>
But the TextInputLayout is taking some more height that the edit text field, I cant align the edit text and the "Km" label vertically the same levels.
As I understand your question check below answer
Give kmLable top and bottom constraint to edit text. Here I give fix width for a temporary purpose (change according to your requirement).
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayoutInputDist"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_margin="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/inputDist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/dividerColor"
android:fontFamily="#font/roboto_bold"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxEms="4"
android:padding="4dp"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/label_km"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#color/dividerColor"
android:fontFamily="#font/roboto_medium"
android:gravity="center_vertical"
android:text="km"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="#+id/textInputLayoutInputDist"
app:layout_constraintStart_toEndOf="#+id/textInputLayoutInputDist"
app:layout_constraintTop_toTopOf="#+id/textInputLayoutInputDist" />
</androidx.constraintlayout.widget.ConstraintLayout>
try
setHintEnabled(false)
in your xml like this:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayoutInputDist"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_margin="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:hintEnabled="false">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/inputDist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/dividerColor"
android:fontFamily="#font/roboto_bold"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxEms="4"
android:padding="4dp"
android:textColor="#color/colorPrimaryDark"
android:textSize="14sp" />
</com.google.android.material.textfield.TextInputLayout>
I have this XML layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layoutDirection="locale"
android:textDirection="rtl"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".app.storey.view.StoreyInsertFragment">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="somthing"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I want hint text show on right side but after use layoutDirection,textAlignment still show on left, how can I do this?
I see this link but not solve my problem.
Use android:textAlignment="viewStart" for TextInputEditText field.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/text_input_user_name"
style="#style/LoginInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginStart="#dimen/margin_editText_end_start"
android:layout_marginTop="#dimen/margin_end_edit_text"
android:layout_marginEnd="#dimen/margin_editText_end_start"
android:layout_marginBottom="#dimen/margin_end_edit_text"
app:hintAnimationEnabled="true"
app:hintEnabled="true"
>
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/edt_user_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|start"
android:gravity="center|start"
android:textAlignment="center"
android:hint="#string/user_name"
android:inputType="textMultiLine"
android:maxLength="8"
android:padding="20dp"
android:textColor="#color/ches_white"
android:textColorHint="#color/ches_white"
android:textSize="#dimen/text_size_login"/>
<android.support.design.widget.TextInputLayout
android:id="#+id/til_name"
style="#style/TextInputLabel2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dimen_20dp"
android:textColorHint="#color/gray_10"
app:hintEnabled="true"
app:hintTextAppearance="#style/CustomTextAppearance2">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/et_name"
style="#style/EditTextStyleWrap"
android:background="#android:color/transparent"
android:backgroundTint="#color/hint_line"
android:digits="#string/accepted_type"
android:gravity="end"
android:inputType="textPersonName"
android:letterSpacing="0.06"
android:maxLength="50"
android:nextFocusLeft="#+id/et_name"
android:nextFocusUp="#id/et_name"
android:textScaleX="1"
android:hint="name"
android:imeOptions="actionNext"
app:et_font="#{#string/font_sans_regular}"
tools:targetApi="lollipop" />
</android.support.design.widget.TextInputLayout>
If you are using api > 17 then try setting below properties to your EditText
android:textDirection="anyRtl"
android:layoutDirection="rtl"
Also, You need to set hint to your EditText and not your TextInputLayout and set gravity to right as mentioned in other answers.