How to make Textinputlayout hint multi-line? - android

I want to make Textinputlayout hint multiline with material outlinedbox even hint in floating mode. I have searched a lot but didn't found any solution can anyone help me how to achieve this task?
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilFieldLabel"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:hintTextAppearance="#style/AddApplicationTextLabel">
<utilities.customcontrols.BodyEditText
android:id="#+id/etValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:gravity="start"
android:inputType="textMultiLine"
android:maxLength="1000"
android:textColor="#color/black"
android:textSize="#dimen/_13ssp"
android:theme="#style/AddApplicationEditTextField"
custom:customfont="bold" />
</com.google.android.material.textfield.TextInputLayout>

TLDR:
Set app:hintEnabled="false" for TextInputLayout
Description:
If you leave hintEnabled to true (true by default) the hint will be single line and turns into a label when the user taps the EditText giving it focus.
If you change hintEnabled to false this feature is removed and the EditText shows the hint with multiple lines as intended. It does not turn into a label and disappears once the user starts actually typing.
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:hintEnabled="false"
app:boxBackgroundMode="none">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Your long hint"/>
</com.google.android.material.textfield.TextInputLayout>
Source: https://stackoverflow.com/a/67744575/13545849

Related

Android EditText with animated hint?

How can I create an Android EditText with a hint like this (with animation)?
So when I tap inside the EditText, the hint shrinks and goes on top of the input text, like in this example:
Use the code given below for all purposes:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/label">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
For Password filed with toggle eye use this:
<com.google.android.material.textfield.TextInputLayout
...
app:endIconMode="password_toggle">
<com.google.android.material.textfield.TextInputEditText
...
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
Learn more from here: https://material.io/components/text-fields/android

How to add a character counter to a material design textfield in Android studio Java

I am trying to add a character counter to a material design textfield, this is the textfield xml code:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextFieldDescripcionUniverso"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="370dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:hint="#string/descripcion"
android:textColorHint="#color/textos"
app:counterEnabled="true"
app:counterMaxLength="150"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/outlinedTextFieldNombreUniverso">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textInputEditTextDescripcionUniverso"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="textMultiLine"
android:textColor="#color/textos" />
</com.google.android.material.textfield.TextInputLayout>
this works nicely and the counter appears,
textfield with counter
but then i want to make the textfield to be vertically bigger, so it works as a textarea where you can write multiple lines and always has the same height. So i change the layout height of textfield and textInputEditText, the code looks like this:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextFieldDescripcionUniverso"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="370dp"
android:layout_height="150dp"
android:layout_marginTop="40dp"
android:hint="#string/descripcion"
android:textColorHint="#color/textos"
app:counterEnabled="true"
app:counterMaxLength="150"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/outlinedTextFieldNombreUniverso">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textInputEditTextDescripcionUniverso"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:inputType="textMultiLine"
android:textColor="#color/textos" />
</com.google.android.material.textfield.TextInputLayout>
bigger textfield without counter
And now the character counter has dissapeared (im assuming its hidden under the textfield). ¿Why doesn't it move to be at the end of the textfield?
¿is there any other way to do this? i have tried normal textfield and the same happens
I think it's because the TextInputLayout has a fixed height as I saw in your code android:layout_height="150dp"
Solution Code :
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextFieldDescripcionUniverso"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="370dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:hint="#string/descripcion"
android:textColorHint="#color/textos"
app:counterEnabled="true"
app:counterMaxLength="150"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/outlinedTextFieldNombreUniverso">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textInputEditTextDescripcionUniverso"
android:layout_width="match_parent"
android:layout_height="150dp"
android:gravity="top"
android:inputType="textMultiLine"
android:textColor="#color/textos" />
</com.google.android.material.textfield.TextInputLayout>
Feel free to ask if something is unclear. And Kindly mark it as the correct answer if it helps you so that in future this answer could help any other needy.😀

Hint Text is overlapping to my TextInputLayout

In my app, I have a TextInputLayout where the user enters its id, when the TextInputLayout does not have the focus looks like:
However, when the user touch the TextInputLayout (get the focus) the hint text looks like:
And I need hint text looks like as the follow image when the TextInputLayout have the focus:
Ignore the icon, its different but it does not matter in this moment, that I want to do is the hint text looks like the last image
Here is my code:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/ilUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:textColorHint="#color/et_login">
<EditText
android:id="#+id/etUser"
android:layout_width="match_parent"
android:layout_height="#dimen/et_login_height"
android:background="#drawable/edit_text_format"
android:drawableLeft="#drawable/user"
android:drawablePadding="10dp"
android:fontFamily="sans-serif"
android:hint="#string/user_id_text_hint"
android:inputType="number"
android:maxLength="12"
android:minLines="15"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textCursorDrawable="#drawable/cursor_drawable_app"
android:textSize="#dimen/h5"
android:theme="#style/EditTextTheme" />
</com.google.android.material.textfield.TextInputLayout>
you cant do this by default edit text you can use some library in your app to apply this ...
library is here :
implementation 'com.google.android.material:material:1.2.1'
and if you want to learn i recommend to see this tutorial :
https://www.youtube.com/watch?v=C_TEugAIMHA&t=616s
see this and you can get your answer...
When you use TextInputLayout is highly recommended to use TextInputEditText instead of EditText
Example:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/ilUser"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="vertical"
android:textColorHint="#color/et_login">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etUser"
android:layout_width="match_parent"
android:layout_height="#dimen/et_login_height"
android:background="#drawable/edit_text_format"
android:drawableLeft="#drawable/user"
android:drawablePadding="10dp"
android:fontFamily="sans-serif"
android:hint="#string/user_id_text_hint"
android:inputType="number"
android:maxLength="12"
android:minLines="15"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textCursorDrawable="#drawable/cursor_drawable_app"
android:textSize="#dimen/h5"
android:theme="#style/EditTextTheme" />
</com.google.android.material.textfield.TextInputLayout>
That should solve it!

TextinputLayout does not display the style correctly if hintEnabled false

I have TIL for entering phone number. The input should be frame so set style. But I need to disable hint animation, I set app:hintEnabled="false" animation work correct, but my border not displayed correctly. Please help
View:
View on focus:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/phone_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
app:hintEnabled="false"
app:hintAnimationEnabled="false"
>
<com.bitnic.loyalitybitnic.widget.FTextInputEditText
android:id="#+id/phone_edit_text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:hint="#string/phone"
app:style_font="medium"
/>
</com.google.android.material.textfield.TextInputLayout>
Update:
If I delete app:hintEnabled="false" then the view displayed correct
Correct view

EditText with custom background turning red using TextInputLayout

I'm using an EditText with a drawable as background and a TextInputLayout
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true"
app:hintEnabled="false">
<EditText
android:id="#+id/input_edittext"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#drawable/input_border"
android:textColor="#color/black"
android:textColorHint="#color/gray" />
</android.support.design.widget.TextInputLayout>
Every time there an error it looks like the error was clear
But when I touch the EditText (doesn't change the focus of the editText) again all the EditText becomes red
For setting the error and clear in the TextInputLayout I'm using
input_layout.setError(getResources().getString(id));
input_edittext.getBackground().clearColorFilter();
Do you have any idea how to solve it? When we don't use the background, it doesn't happen

Categories

Resources