like this:
The words email or phone are the hint which jumps to top on gaining focus. i tried searching for a library and even looking into code of text input layout, but couldn't understand how to get something like that???
To get that general appearance, all you have to do is apply the "outline" style to your TextInputLayout tag:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
...>
<com.google.android.material.textfield.TextInputEditText
.../>
</com.google.android.material.textfield.TextInputLayout
The "Email or phone" text that jumps to the top is the "hint" text set on the layout.
<com.google.android.material.textfield.TextInputLayout
android:hint="Email or phone"
...>
Developer guide for TextInputLayout: https://material.io/develop/android/components/text-input-layout/
You will need the Google Material Components library in your app. Getting started guide: https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md
Related
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?
I want to create a text field where the label is inside the borders, something like this:
How can I do this with the material components?
I don't want to have the label between the border like this: (doesn't look nice anymore when you have multiple filled fields, it's to nervous with all the interrupted borders in my opinion)
A simple thing you could do is to move the hint into the TextInputEditText and disable it on the TextInputLayout.
Then it behaves like the old EditTexts: The line doesn't get interrupted because the hint disappears when the user starts typing. You could use app:helperText if you need to show text permanently (or maybe put a TextView on top).
There are other ways to get the perfect result, but they seem "hacky". Like this and this.
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:hintEnabled="false"
app:helperText="helperText"
... >
<com.google.android.material.textfield.TextInputEditText
android:hint="hint"
... />
</com.google.android.material.textfield.TextInputLayout>
I am trying to add clear icon in edit text box right side corner and able to clear the typed text using text watcher functionality in Android.
At the same I am trying in for Floating label edittext inside. But, I could not able to add the clear icon/button on right side corner of TextInputEditText.
Note: I have tried onDrawableRight image adding with onTouchListener method, some of the situation not work out for me.
Just use the TextInputLayout with the pre-packaged app:endIconMode="clear_text" attribute.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/custom_end_icon"
android:hint="Hint text"
app:endIconMode="clear_text"
...>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
../>
</com.google.android.material.textfield.TextInputLayout>
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.
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.