Duplicate error icon on TextView/TextInputEditText [duplicate] - android

I have an EditText as password input like this
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
It's working, but when there's an error the error icon shwon twice and it's on top of show password icon.
My validation code to show the error :
if (success) {
finish();
startMainActivity();
} else {
mPasswordView.setError(getString(R.string.error_incorrect_password));
mPasswordView.requestFocus();
}

Don't call setError on the EditText, use TextInputLayout's setError()

Same behavior for material version 1.1.0-alpha10, even if you set an error into TextInputLayout. You can avoid it by adding to the TextInputLayout this line :
app:errorIconDrawable="#null"

With this code, you can remove toggle while showing the error. you can show toggle while user writing anything. Don't remember, you should give id to text input layout
public void showError(){
password.setError(errorMessage);
password.requestFocus();
textInputLayout.setPasswordVisibilityToggleEnabled(false);
}
password.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
textInputLayout.setPasswordVisibilityToggleEnabled(true);
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void afterTextChanged(Editable editable) {
}
});

please add these two lines in edittext
android:layout_marginEnd="9dp"
android:paddingRight="40dp"

Simple solution
private static Drawable error;
error = getResources.getDrawable(R.drawable.nameOfIcon);
// use set bounds, here we use this to remove overlapping between error icon and password toggle.
error.setBounds(-50,0,0,error.getIntrinsicHeight());
// error icon will show 50dp from right
editTextName.setError("error string",error);

It seems that it is a bug after updating gradle dependencies to 24+.
Please, check this answer. I had all my setError() working fine before that. Plus, you hadn't to ask for focus in order to display the error.

<com.google.android.material.textfield.TextInputEditText
android:paddingEnd="40dp"
android:inputType="textPassword"
/>

Related

Error message icon and Password toggle icon overlapping in Android EditText [duplicate]

I have an EditText as password input like this
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
It's working, but when there's an error the error icon shwon twice and it's on top of show password icon.
My validation code to show the error :
if (success) {
finish();
startMainActivity();
} else {
mPasswordView.setError(getString(R.string.error_incorrect_password));
mPasswordView.requestFocus();
}
Don't call setError on the EditText, use TextInputLayout's setError()
Same behavior for material version 1.1.0-alpha10, even if you set an error into TextInputLayout. You can avoid it by adding to the TextInputLayout this line :
app:errorIconDrawable="#null"
With this code, you can remove toggle while showing the error. you can show toggle while user writing anything. Don't remember, you should give id to text input layout
public void showError(){
password.setError(errorMessage);
password.requestFocus();
textInputLayout.setPasswordVisibilityToggleEnabled(false);
}
password.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
textInputLayout.setPasswordVisibilityToggleEnabled(true);
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void afterTextChanged(Editable editable) {
}
});
please add these two lines in edittext
android:layout_marginEnd="9dp"
android:paddingRight="40dp"
Simple solution
private static Drawable error;
error = getResources.getDrawable(R.drawable.nameOfIcon);
// use set bounds, here we use this to remove overlapping between error icon and password toggle.
error.setBounds(-50,0,0,error.getIntrinsicHeight());
// error icon will show 50dp from right
editTextName.setError("error string",error);
It seems that it is a bug after updating gradle dependencies to 24+.
Please, check this answer. I had all my setError() working fine before that. Plus, you hadn't to ask for focus in order to display the error.
<com.google.android.material.textfield.TextInputEditText
android:paddingEnd="40dp"
android:inputType="textPassword"
/>

How to make TextInputLayout with red astrisk mark

I am trying to make mandatory field with the use of TextInputLayout. I used Spannable class but display the hint of TextInputLayout in single color.I want my view to look something like in below link.
https://material.io/guidelines/components/text-fields.html#text-fields-search-filter
I have created the following TextInputEditText to look as similar as possible to the Material Design Text Field.
XML Layout
<android.support.design.widget.TextInputLayout
android:id="#+id/etlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="25">
<android.support.design.widget.TextInputEditText
android:id="#+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:layout_marginLeft="-4dp"
android:layout_marginStart="-4dp"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:inputType="text|textCapSentences"
android:singleLine="true"
android:hint="#string/title"
android:textColorHint="#color/transparent38"/>
</android.support.design.widget.TextInputLayout>
Color
<color name="transparent38">#66000000</color>
Java
etlayout = (TextInputLayout)findviewbyid(R.id.etlayout);
TextWatcher twTitle = new TextWatcher() { //Analyzes when the view changes
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (true) { //Replace condition with validity test
etlayout.setErrorEnabled(false); //Removes the extra space
etlayout.setError(null); //Removes the error message
} else { //If the text is not valid
etlayout.setErrorEnabled(true); //Makes the space for the error appear
etlayout.setError("Invalid input"); //Shows a message
}
}
#Override
public void afterTextChanged(Editable s) {
}
};
etTitle.addTextChangedListener(twTitle);

Edittext set error twice [duplicate]

I have an EditText as password input like this
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
It's working, but when there's an error the error icon shwon twice and it's on top of show password icon.
My validation code to show the error :
if (success) {
finish();
startMainActivity();
} else {
mPasswordView.setError(getString(R.string.error_incorrect_password));
mPasswordView.requestFocus();
}
Don't call setError on the EditText, use TextInputLayout's setError()
Same behavior for material version 1.1.0-alpha10, even if you set an error into TextInputLayout. You can avoid it by adding to the TextInputLayout this line :
app:errorIconDrawable="#null"
With this code, you can remove toggle while showing the error. you can show toggle while user writing anything. Don't remember, you should give id to text input layout
public void showError(){
password.setError(errorMessage);
password.requestFocus();
textInputLayout.setPasswordVisibilityToggleEnabled(false);
}
password.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
textInputLayout.setPasswordVisibilityToggleEnabled(true);
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void afterTextChanged(Editable editable) {
}
});
please add these two lines in edittext
android:layout_marginEnd="9dp"
android:paddingRight="40dp"
Simple solution
private static Drawable error;
error = getResources.getDrawable(R.drawable.nameOfIcon);
// use set bounds, here we use this to remove overlapping between error icon and password toggle.
error.setBounds(-50,0,0,error.getIntrinsicHeight());
// error icon will show 50dp from right
editTextName.setError("error string",error);
It seems that it is a bug after updating gradle dependencies to 24+.
Please, check this answer. I had all my setError() working fine before that. Plus, you hadn't to ask for focus in order to display the error.
<com.google.android.material.textfield.TextInputEditText
android:paddingEnd="40dp"
android:inputType="textPassword"
/>

EditText error icon and show password missplaced

I have an EditText as password input like this
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
It's working, but when there's an error the error icon shwon twice and it's on top of show password icon.
My validation code to show the error :
if (success) {
finish();
startMainActivity();
} else {
mPasswordView.setError(getString(R.string.error_incorrect_password));
mPasswordView.requestFocus();
}
Don't call setError on the EditText, use TextInputLayout's setError()
Same behavior for material version 1.1.0-alpha10, even if you set an error into TextInputLayout. You can avoid it by adding to the TextInputLayout this line :
app:errorIconDrawable="#null"
With this code, you can remove toggle while showing the error. you can show toggle while user writing anything. Don't remember, you should give id to text input layout
public void showError(){
password.setError(errorMessage);
password.requestFocus();
textInputLayout.setPasswordVisibilityToggleEnabled(false);
}
password.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
textInputLayout.setPasswordVisibilityToggleEnabled(true);
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void afterTextChanged(Editable editable) {
}
});
please add these two lines in edittext
android:layout_marginEnd="9dp"
android:paddingRight="40dp"
Simple solution
private static Drawable error;
error = getResources.getDrawable(R.drawable.nameOfIcon);
// use set bounds, here we use this to remove overlapping between error icon and password toggle.
error.setBounds(-50,0,0,error.getIntrinsicHeight());
// error icon will show 50dp from right
editTextName.setError("error string",error);
It seems that it is a bug after updating gradle dependencies to 24+.
Please, check this answer. I had all my setError() working fine before that. Plus, you hadn't to ask for focus in order to display the error.
<com.google.android.material.textfield.TextInputEditText
android:paddingEnd="40dp"
android:inputType="textPassword"
/>

cursor in EditText hint does not start from right for Arabic

I'm trying to make EditText with a hint text:
In English "password" .. the cursor is correctly set to the left.
But for Arabic for which the hint is "كلمه المرور" the cursor is always set to the left (the end of the hint) instead of the right.
<EditText
android:id="#id/ETPass"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/etUsrName"
android:layout_marginLeft="#dimen/_25sdp"
android:layout_marginRight="#dimen/_25sdp"
android:layout_marginTop="#dimen/_5sdp"
android:background="#drawable/signup_edittext_input"
android:ellipsize="start"
android:gravity="center|right"
android:hint="#string/Password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:paddingRight="#dimen/_5sdp"
android:singleLine="true"
android:textColor="#color/orange"
android:textColorHint="#color/orange" />
This happens only for android:inputType="textPassword" . Everything works fine for a normal text inputType.
For Android 17 and higher(4.2.+) its working:
android:textAlignment="viewStart"
Try:
android:textDirection="rtl"
xml code
<EditText
android:maxLength="#integer/lockMaxLen"
android:inputType="textPassword"
android:layout_width="180dip"
android:gravity="right|center"
android:hint="#string/lock_pass_hint"
android:layout_height="45dip"
android:id="#+id/lockPassword" />
in oncreate
passwordEditText.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence currentDigits, int start,
int before, int count) {
if (passwordEditText.getText().toString().length() == 0)
passwordEditText.setGravity(Gravity.RIGHT);
else
passwordEditText.setGravity(Gravity.LEFT);
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
Use both, to resolve the alignment issue (even in Samsung device also)
android:textAlignment="viewStart"
android:textDirection="rtl"
Maybe I am late, but I faced the same issue. I resolved the issue with the following workaround.
// Get Current language
public static String getCurrentLanguage(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getString(CURRENT_LANGUAGE, "");
}
// Check if the language is RTL
public static boolean isRTL(String locale) {
return TextUtilsCompat.getLayoutDirectionFromLocale(new Locale(locale)) == ViewCompat.LAYOUT_DIRECTION_RTL ? true : false;
}
// Set gravity to the right
private void repositionPasswordTextInArabic(){
if( LocaleSettings.isRTL(LocaleSettings.getCurrentLanguage(this))){
password.setGravity(Gravity.RIGHT);
}
}
editText.setSelection(editText.getText().length());

Categories

Resources