Is is possible to set error on Text Input Layout without showing any error message (i'm already doing it in another place)?.
textinputlayout.setError("");
won't work unfortunately.
What i basically need is the textInputLayout to change its line color to red, but i need to do it programmatically. Thank you
You can hide the layout with error like this:
textinputlayout.setError("");
if (textinputlayout.getChildCount() == 2) {
textinputlayout.getChildAt(1).setVisibility(View.GONE);
}
Hope it's not too late, but the code behind setError is:
if (!mErrorEnabled) {
if (TextUtils.isEmpty(error)) {
// If error isn't enabled, and the error is empty, just return
return;
}
}
this means a simple workaround would be:
textinputlayout.setError(" ");
please be advised, that this will make TextView with error message visible - so it will make TextInputLayout higher even if it will be empty
since this passes the not-so-well-thought-out case of handling an empty error message request.
The error text (even " ") will take/reserve some height in the TextInputLayout. If you also want to get rid of it then
<com.google.android.material.textfield.TextInputLayout
...
app:errorTextAppearance="#style/MyZeroSizeTextAppearance"
...
>
Text appearance:
<style name="MyZeroSizeTextAppearance">
<item name="android:textSize">0sp</item>
</style>
and then
textinputlayout.setError(" ");
Related
I have written some code for showing a Dialog box using sweet alert library. It's a very popular library and contains couple of awesome features which are very useful for designing purpose and developing purpose as well. So please help to change the background color of Action button which are present at the bottom of the dialog box.
I am attaching the screen shot and as well as code. Please help me to fix this issue.
I only want to change the background color of Action Button.
MaterialDialog.Builder builder = new MaterialDialog.Builder(SignInActivity.this)
.title("Sign Up")
.titleColor(Color.BLACK)
.customView(R.layout.custom_dialog_sign_up, true)
.positiveText("Submit")
.negativeText("Cancel")
.positiveColorRes(R.color.black_color)
.negativeColorRes(R.color.gray_btn_bg_color)
.canceledOnTouchOutside(false)
.autoDismiss(false);
final MaterialDialog materialDialog = builder.build();
materialDialog.show();
it is pretty late to respond upon your question but, recently i face this issue and start digging about it on google but found nothing, so i started my own and found this perfect solution code and screen shot attached.
SweetAlertDialog sweetAlertDialogView;
sweetAlertDialogView = new SweetAlertDialog(ctx,SweetAlertDialog.ERROR_TYPE);
sweetAlertDialogView.setTitleText(ctx.getResources().getString(R.string.error_msg_oops_title))
.setContentText("Request failed :" + errMsg + " \n" + ctx.getResources().getString(R.string.error_msg_check_net_connection));
sweetAlertDialogView.show();
Button viewGroup = (Button) sweetAlertDialogView.findViewById(cn.pedant.SweetAlert.R.id.confirm_button);
if (viewGroup != null) {
Log.e(TAG, "showErrorMsg: Button view Found yep");
viewGroup.setBackgroundColor(viewGroup.getResources().getColor(R.color.colorSkyBlueButtonLoader));
} else {
Log.e(TAG, "showErrorMsg: Button view Null :( ");
}
from above logic i update the button color to dark sky blue blue, for any other help you can ask me in comment. i will try to resolve it with my best.
A far more easier way to accomplish this is to just overwrite following color values in your color.xml:
<color name="blue_btn_bg_color">#1976D2</color>
<color name="blue_btn_bg_pressed_color">#1565C0</color>
I am using EditText with TextInputLayout. This is the code, that I am using to display error.
private boolean validateEmail() {
String email = inputEmail.getText().toString().trim();
if (email.isEmpty() || !isValidEmail(email)) {
inputLayoutEmail.setErrorEnabled(true);
inputLayoutEmail.setError(getString(R.string.err_msg_email));
requestFocus(inputEmail);
return false;
} else {
inputLayoutEmail.setErrorEnabled(false);
}
return true;
}
I am calling this method in edittext's textwatcher like in this link http://www.androidhive.info/2015/09/android-material-design-floating-labels-for-edittext/
Once I entered a valid input then clear that ,it will show error message as expected,But it wont work if i enter the text again and then clear it again.ie.It is not showing any error message.
I am using compile 'com.android.support:design:23.1.0' library.
inputLayoutEmail.setErrorEnabled(true);
is calling but error is not displaying. What might be the problem? How I can solve this?
In your layout file, ensure you have layout_height="wrap_content" for the TextInputLayout
instead of a dimension. This was causing the issue for me.
You just need apply,
inputLayoutEmail.setErrorEnabled(false);
inputLayoutEmail.setError(null);
It worked for me. Hope it will work for you too.
The example worked for me.
you use
compile 'com.android.support:design:23.1.0'
and the right one is
compile 'com.android.support:design:23.0.1'
I was having same issue and i was using data binding so adding below line solved my issue :
app:errorEnabled="true"
Use Android Support Library, revision 23.4.0 (May 2016)
Fixed an issue where TextInputLayout doesn't clear error tint after setErrorEnabled(false) on API level 21 - 22 (Issue 202829)
I have a vertical linear layout with some input fields. Using TextInputLayout I get a nice flow with labels and built-in error messages. My problem is when I add and remove the error-messages.
If I add an error message it is positioned below the edit-text and everything looks good.
If I remove the error message with setError(null) the message is removed but the space is still there. This is per googles design apparently(see https://code.google.com/p/android/issues/detail?id=176005). I would very much like this space removed as it makes the UI look very wrong.
If I do .setErrorEnabled(false) the view is removed and everything looks normal again. However if the user changes the data and I do another setError the error-message is not shown (only the edit text line is red).
As of Support library version 23.1.1 (and perhaps earlier), this should no longer be the case. You should be able to call TextInputLayout.setErrorEnabled(false) to hide the error TextView and calling TextInputLayout.setError(error) now internally calls TextInputLayout.setErrorEnabled(true) if the error isn't null or empty. See the code snippet below, taken from the support library:
public void setError(#Nullable CharSequence error) {
if (!mErrorEnabled) {
if (TextUtils.isEmpty(error)) {
// If error isn't enabled, and the error is empty, just return
return;
}
// Else, we'll assume that they want to enable the error functionality
setErrorEnabled(true);
}
...
}
For me, below code is working fine.
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(mobileNoInputLayout.isErrorEnabled()){
mobileNoInputLayout.setErrorEnabled(false);
}
}
I am developing soft keyboard every thing works fine but when i change orientation following error occurs
"Unexpected null in startExtractingText : mExtractedText = null, input connection = com.android.internal.view.InputConnectionWrapper"
and close the inputview as well
i don't know how to solve this please help.
I found problem
when External application force close Input-view it will throw
start extracting text null
I have faced the same issue. I have resolved this issue. In my case , I was adding my custom view on overrided method setExtractView(View view). But I was not removing views first.
Let me explain :
#Override
public void setExtractView(View view) {
// You have to do this if you are not doing so
view.removeAllViews() ; // This is the line
view.addView(yourView) ; // Here you can put your own Custom view
super.setExtractView(view);
}
This is working for me.I hope this will help you.
Is there any way to set a custom layout for an error popup window in TextView:
.
In textView.setError(String, Drawable) we can set an error icon only.
showError() method in TextView and ErrorPopup class are private, so I can't work with them.
Any ideas? Thanks in advance! Michael
UPD:
Thanks for comments, but as I understand it, the theme trick isn't applicable here:
(TextView 3384 line from android-10)
void fixDirection(boolean above) {
mAbove = above;
if (above) {
mView.setBackgroundResource(com.android.internal.R.drawable.popup_inline_error_above);
} else {
mView.setBackgroundResource(com.android.internal.R.drawable.popup_inline_error);
}
}
In android-15 com.android.internal.R.styleable.Theme_errorMessageBackground theme parameter is used, but it is internal.
Therefore I don't see any way to solve this problem, except writing my own error notificator ):