Android TextInputEditText doesn't focus on cursor position - android

When trying to edit long text inside TextInputEditText, the focus goes always to the bottom, so the top (where actually the cursor is) stays out of the screen and you cannot see actually what you are typing. See a GIF showing the TextInputEditText problem that I describe.
My xml:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notes"
app:boxBackgroundColor="#android:color/transparent"
app:hintAnimationEnabled="false"
app:passwordToggleEnabled="false">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/notes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notes"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine" />
</com.google.android.material.textfield.TextInputLayout>
Material library version:
implementation 'com.google.android.material:material:1.5.0'

The issue has been fixed with this commit so using the latest beta release seems to be working just fine:
implementation 'com.google.android.material:material:1.6.0-beta01'

Related

Error in text showing ontop of suffix in TextInputLayout in andrfoid

i have a project, that i'm using
<com.google.android.material.textfield.TextInputLayout
i'm using it like that >
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
id="#+id/TextInputLayoutId
app:suffixText="suffeix_forText_input"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/TextInputEditTextId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/vitals_diastolic"
android:inputType="number"
android:maxLength="3"/>
</com.google.android.material.textfield.TextInputLayout>
but when i run into an error, the text and icon of the error are both on top of each other
i am using
the latest
api 'com.google.android.material:material:1.6.1'
it is a bonded view if it matters
do you know why this is happening that the text overlapping?
i am
this is the Error shown from the TextInputEditText

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 with OutlinedBox stroke overlaps the hint

I use com.google.android.material:material:1.1.0 and trying to make EditText with outlined box with a hint. My issue is that stroke of the box is overlaps the hint:
Here is my code:
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxStrokeWidth="1dp"
app:hintEnabled="true">
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="#+id/export_csv_sep_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="130dp"
android:layout_gravity="bottom"
android:digits=",;:.|/*-_"
android:fontFamily="sans-serif"
android:gravity="center"
android:imeOptions="actionDone|flagNoFullscreen|flagNoExtractUi"
android:inputType="text"
android:maxLength="1"
android:maxLines="1"
android:selectAllOnFocus="true"
android:singleLine="true"
android:text=","
android:hint="#string/separator"
android:textColor="?android:textColorPrimary"
android:textSize="#dimen/normal_font_size"
android:completionThreshold="1"/>
</com.google.android.material.textfield.TextInputLayout>
Is it bug in the material library, or something wrong with my code?
It depends by the use of android:gravity="center"
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:gravity="center"
..>
Starting from 1.2.0-alpha02 the bug is fixed and there is a different behavior.
In any case use MaterialAutoCompleteTextView or AutoCompleteTextView instead of androidx.appcompat.widget.AppCompatAutoCompleteTextView (there is an auto-inflation of MaterialAutoCompleteTextView using AutoCompleteTextView).
Something like:
<com.google.android.material.textfield.TextInputLayout
...
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
.....
/>
</com.google.android.material.textfield.TextInputLayout>
It seems there are quite some bugs with version 1.1.0
For now they have addressed some in the latest release, update your version to latest one (see latest releases here)
For now latest release is : 1.2.0-alpha06
Or use below in your app gradle :
implementation 'com.google.android.material:material:1.2.0-alpha06
Refer here for issues reported for material components or you can raise one yourselves

How to remove white box from TextInputLayout

Today I have just updated my dependencies of material design
from 1.0.0 to 1.1.0-alpha09
implementation 'com.google.android.material:material:1.1.0-alpha09'
Now i"m getting strange issue in com.google.android.material.textfield.TextInputLayout
Here is my Code
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/emailTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_10sdp">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/emailTextInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_enter_email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"/>
</com.google.android.material.textfield.TextInputLayout>
after updating the dependencies I'm getting boxed design in my TextInputLayout
Output of above code
if i use implementation 'com.google.android.material:material:1.0.0' I'm getting expected result
Can anybody help me to solve this issue
If need more information please do let me know. Thanks in advance. Your efforts will be appreciated.
UPDATE
I have already tried app:boxBackgroundMode="none" them I'm getting this
,
if i use app:boxBackgroundMode="outline" then getting this
SOLVED
No need to use boxBackgroundMode
You need to add #style/Widget.Design.TextInputLayout in your TextInputLayout
SAMPLE CODE
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/emailTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_10sdp"
style="#style/Widget.Design.TextInputLayout"
app:errorTextAppearance="#style/error_appearance"
android:textColorHint="#android:color/white">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:id="#+id/emailTextInputEditText"
android:layout_height="wrap_content"
android:backgroundTint="#android:color/white"
android:gravity="center"
android:hint="#string/hint_enter_email"
android:imeOptions="actionNext"
android:textColorHint="#android:color/white"
android:inputType="textEmailAddress"
android:textColor="#android:color/white"
android:textSize="#dimen/_15ssp"/>
</com.google.android.material.textfield.TextInputLayout>
OUTPUT
To revert back to old style with no filed background but only bottom border, one should use following style:
<com.google.android.material.textfield.TextInputLayout
...
style="#style/Widget.Design.TextInputLayout"
....
>
</com.google.android.material.textfield.TextInputLayout>
Using theme Widget.Design.TextInputLayout will generate expected output like below:
Using a material Theme the default style used by the TextInputLayout is #style/Widget.MaterialComponents.TextInputLayout.FilledBox
To obtain something similar just change the background color using the boxBackgroundColor attribute:
<style name="CustomFilledBox" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="boxBackgroundColor">#myColor</item>
</style>
Also use the android:hint="#string/hint_enter_email" in the TextInputLayout not in the TextInputEditText
For me using #style/Widget.Design.TextInputLayout produced undesirable formatting results, specifically alignment issues with the editText box.
I used boxBackgroundMode set to none for awhile, and after updating material design in my project the error icon mentioned started showing. May be a bug (https://issuetracker.google.com/issues/122445449).
For now I'm still setting the boxBackgroundMode to none, and hiding the error icon by setting the color to transparent. This way I keep the material design.
app:boxBackgroundMode="none"
app:errorIconTint="#android:color/transparent"
<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
app:boxBackgroundMode="none"
app:errorIconTint="#android:color/transparent"
app:hintEnabled="false">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/message_ellipsis"
android:inputType="textCapSentences|textMultiLine"
android:paddingTop="10dp" />
</com.google.android.material.textfield.TextInputLayout>
Set this in your TextInputLayout:
app:boxBackgroundMode="none"
Probably you have set boxBackgroundMode to filled or maybe it's set by default. Just add above line, and this should fix the issue.
Same behavior with com.google.android.material:material:1.3.0
Applying transparent background to TextInputEditText does the tricks.
android:background="#android:color/transparent"

Left Icon in TextInputLayout

I'm trying to add an Left Icon to my TextInputLayout, but text get over the Icon.
When I add a padding, everything move together.
I tried with
android:drawableLeft="#drawable/ic_store_white_48dp"
android:drawablePadding="50dp"
android:drawableStart="#drawable/ic_store_white_48dp"
But it is not working !
I should implement a LinearLayout horizontal for each row, but I would like to be sure there is no easier way to do it
Here is my code layout:
<android.support.design.widget.TextInputLayout
android:id="#+id/til_calle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/et_calle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_store_white_48dp"
android:drawablePadding="50dp"
android:drawableStart="#drawable/ic_store_white_48dp"
android:hint="Calle"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
Make sure you are using the latest Design library, all you need for both Design and AppCompat is:
compile 'com.android.support:design:23.2.0'
Try using both the Design's library TextInputLayout and AppCompat's AppCompatEditText.
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#android:color/white"
android:textColorHint="#color/loginHint">
<android.support.v7.widget.AppCompatEditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="textEmailAddress|textNoSuggestions"
android:minWidth="350dp"
android:drawableLeft="#drawable/ic_store_white_48dp"
android:drawableStart="#drawable/ic_store_white_48dp"
android:textColor="#android:color/white"
android:textColorHint="#color/loginHint"
android:textCursorDrawable="#null"
app:backgroundTint="#android:color/white"/>
</android.support.design.widget.TextInputLayout>
With the Material Components library you can change the left icon in the TextInputLayout using the app:startIconDrawable attribute.
Something like:
<com.google.android.material.textfield.TextInputLayout
android:hint="Hint text"
app:startIconDrawable="#drawable/ic_add_24px"
...>
<com.google.android.material.textfield.TextInputEditText/>
</com.google.android.material.textfield.TextInputLayout>
Here is my code layout:
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_username"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/input_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:drawableLeft="#drawable/icon_user"
android:drawableStart="#drawable/icon_user"
android:drawablePadding="10dp"
android:hint="User Name" />
</android.support.design.widget.TextInputLayout>
android:drawablePadding="10dp"
Its work
This is a bug that was reported on Android's Issue Tracker
https://code.google.com/p/android/issues/detail?id=225836
and it's now been fixed on the latest release of the Design Support Library (v25.0.1). Just add the required dependency to the build gradle...
dependencies {
compile 'com.android.support:design:25.0.1'
}
It is simple, when adding passwordToggleEnabled it automatically adding the eye icon on the right and the drawableLeft was gone. so you have to remove the drawableLeft and just use the drawableStart.
<android.support.design.widget.TextInputLayout
android:id="#+id/til_calle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/et_calle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawablePadding="50dp"
android:drawableStart="#drawable/ic_store_white_48dp"
android:hint="Calle"
android:inputType="text" />
If you are using material input layout so you just need to add one line in input layout's xml code
app:startIconDrawable="#drawable/ic_baseline_content_paste_24"
Yes. Currently its a bug on Layout.
You can try giving leftPadding to EditText or give some blank_spaces before the text.
Using material library, you can set custom icon using endIconMode="custom":
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/date_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:endIconMode="custom"
app:endIconDrawable="#drawable/ic_calendar">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/date_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
android:textSize="14sp"
tools:text="30 feb" />
</com.google.android.material.textfield.TextInputLayout>

Categories

Resources