How to get Textinputlayout hint android in multiple lines? - android

I have tried many options available online but none of them seem to be working.
I have used this XML for this purpose.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="#style/TextLabel">
<com.projects.fonts.RobotoEditText
style="#style/EditText"
android:hint="#string/description"
android:singleLine="false"
app:font="#string/roboto_regular" />
</android.support.design.widget.TextInputLayout>
I have also set
<item name="android:singleLine">false</item>
in both TextLabel and EditText. But none of them are working.

You can't.
TextInputLayout uses CollapsingTextLayout which measures the hint as a CharSequence:
mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length())
CharSequence has no notion of a line, thus you can't add more.
It's not quite a hint if it's so long.
If you still want to display it consider adding a separate TextView below/above/over and animating it (if want/need to).

You can do this with TextInputLayout and TextInputEditText.
In the TextInputEditText set the hint as you normally would (android:hint="Hint Text").
In the TextInputLayout you must disable the hint by setting "app:hintEnabled="false".
Notes:
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.
Example code below:
<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>

In contrast to simas answer it seems that there is a workaround. You can achieve the expected behaviour by setting the hint programmatically in the TextInputEdittext. The downhill is that the floating label does not work after that, by I believe that it is not something that we expect with so long hint.
Important note: If we set the hint to the TextInputLayout, then it will not work.

Related

Displaying keyboard below the the selected line using multi-line TextField

so I've got the following layout with the following TextInputEditText :
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/note"
android:layout_marginTop="#dimen/layout_margin_default"
app:startIconDrawable="#drawable/baseline_notes_24">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
/>
</com.google.android.material.textfield.TextInputLayout>
Right now, when I select to write inside the TextInputEditText the keyboard automatically displays below the TextInputEditText:
Now, what I want to is that rather displaying the keyboard below the TextInputEditText, I want the display to keyboard below the current "selected" line, which should look like this:
Example video how it should look like:
https://jumpshare.com/v/TAO6jo1jdnRZDhYyzrkY
How can this be solved in the right way?
I've tried using android:windowsoftinputmode, but I couldn't find the appropriate attribute.
I'm assuming there is not much leeway when it comes to the displaying the keyboard?

How to change visiblity (visible, invisible or gone ) of setEndIconDrawable in TextInputLayout android?

I am trying to make invisible or visibility gone of endIconDrawable which is the edit icon in the picture above for FirstName field only and want to keep visibile edit icon rest of the fields but unable to do? How can i do this?
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilFirstName"
android:layout_width="match_parent"
android:layout_height="#dimen/_64dp"
app:endIconDrawable="#drawable/icon_edit"
app:endIconMode="custom">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:hint="#string/label_fname"
android:inputType="textCapWords" />
</com.google.android.material.textfield.TextInputLayout>
I wanted to get the following as shown in the below image:
If you want to do it in the layout (static way) just don't add the app:endIconDrawable/app:endIconMode attributes:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilFirstName"
android:layout_width="match_parent"
android:layout_height="#dimen/_64dp">
Programmatically to remove the endIconDrawable you can use:
textInputLayout.setEndIconMode(TextInputLayout.END_ICON_NONE);
To add the endIconDrawable you can use:
textInputLayout.setEndIconMode(TextInputLayout.END_ICON_CUSTOM);
textInputLayout.setEndIconDrawable(R.drawable.xxxx);
I tried #Gabriele Mariotti 's answer. It's good but it has a problem. I used the code for making endicon visible or invisible in text watcher and it didn't work as desired. Then I used isEndIconVisible attribute for textInputLayout and maje it true or false. It works correctly as desired.
2022 KOTLIN
best solution:
textInputLayout.isEndIconVisible = false
Add this android:visibility="gone"

Why edit text is underlined?

EditText is disabled, but still it is underlined. Why, how can I remove underline? What exactly underline means? In iOS same component is UITextView but it never underline so the control.
<EditText
android:layout_width="305dp"
android:layout_height="79dp"
android:inputType="textMultiLine"
android:ems="10"
android:layout_below="#+id/view"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:id="#+id/editText5"
android:text="Do you know y.."
android:enabled="false" />
EditText is disabled
Use a TextView instead.
how can I remove underline?
Use a TextView instead.
Or, use a different background for the EditText, probably. I assume that the Theme.Material/Theme.AppCompat way of supplying that bracket is via the background, as it was with Theme and Theme.Holo. I have not changed the background of an EditText in years, as usually it is not needed.
What exactly underline means?
It tells humans that this represents text that they can edit, as opposed to text that they cannot edit.

Text input is white

One of the users of my app is having an issue where the text he enters in the EditText elements of my app is white, which effectively renders it invisible against a white background. He's the only user experiencing this issue, and it's only happening to him in my app.
As an example, here's the code for one of my EditText elements:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/usernameTextBox"
android:imeOptions="actionDone"
android:singleLine="true"/>
There are dozens of these in my app, and all are essentially coded the same. Any ideas why this might be happening?
Every android distribution can overwrite default colors for widget. Therefore, if you want all of your EditText to look the same you should explicitly set their background and text color like so:
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/usernameTextBox"
android:imeOptions="actionDone"
android:singleLine="true"
android:background="#FFFFFF"
android:textColor="#000000"/>
To ensure that the text colour being displayed correctly, strictly set the textColor attribute for each declared TextView like so android:textColor="#android:color/black"

EditText added is not a TextInputEditText. Please switch to using that class instead

I'm using an EditText inside a TextInputLayout, but after upgrading the support library to 23.2.0, I get this warning in the logcat, What's the difference between a regular EditText and a TextInputEditText? I can't seem to find any documentation for it.
I was wondering this too, Daniel Wilson gathered the documentation, but to the untrained eye it doesn't mean much. Here's what it's all about: "extract mode" is referring to the type of view that's shown when the space is too small, for example landscape on a phone. I'm using Galaxy S4 with Google Keyboard as input method editor (IME).
Landscape UI without visible IME
Based on the focus (on Description) you can see TextInputLayout in action pushing the hint outside the editor. Nothing special here, this is what TextInputLayout is supposed to do.
Landscape UI editing empty Name field
Editing the Name you can see that the IME doesn't give you a hint of what you're editing.
Landscape UI editing empty Description field
Editing the Description you can see that the IME gives you a hint of what you're editing.
Layout XMLs
The difference between the two fields is their type EditText VS TextInputEditText. The important thing here is that TextInputLayout has the android:hint and not the wrapped EditText, this is the case when TextInputEditText's few lines of Java code makes a big difference.
Name field
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Item Name"
>
<EditText
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.TextInputLayout>
Description field
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Item Description"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="4"
android:scrollbars="vertical"
/>
</android.support.design.widget.TextInputLayout>
There is no documentation for it, but the class is a regular EditText with a single extra feature:
Using this class allows us to display a hint in the IME when in 'extract' mode.
Specifically it sets the EditorInfo.hintText. You'll notice in the TextInputLayout class you can specify the hint and it's appearance rather than as part of the child EditText widget.
If you need to do that, you should use a TextInputEditText so it pays attention to the hint info you specified in the TextInputLayout.
They are essentially the same thing, but I think the TextInputEditText has more features and possibly attributes. I changed to the TextInputEditText and everything worked and looked as it did before with the standard EditText.
The only difference is that when your device is in landscape mode, TextInputEditText will show the hint, EditText won't.
I had this problem and just deleted this line in my xml file:
android: fitsSystemWindows = "true"
and the error disappeared.

Categories

Resources