Question

Background

On Android, you can set an error indication for any EditText view when you want to show the user that what is typed there (or not typed) is wrong (called "form validations").

There is even a nice library for this (here) , and many post here are available of how to use it.

All worked well for me till I've ran it on a nexus 4 with Android 4.2 .

The problem

Sometimes, it just won't show the icons of the errors. In such a case , only when i give the editText (that has the problem) focus, it shows the bubble, but it's empty and doesn't show the icon of the error.

Also, in all cases, the bubbles are always empty.

Why does it occur, and how can I fix it?

Note: I use actionBarSherlock library so I need to use their themes or a theme that is based on theirs.


EDIT:

here are some screenshots:

android 4.2.2 :

enter image description here

android 2.3.5 :

enter image description here


EDIT:

after i thought that this was solved by itself, i've finally figured out when this bug occurs: if the focus is on another editText which doesn't have an error, and the error of validation is on another editText , the indicator isn't shown till the editText gets focus.

Was it helpful?

Solution

Problem 1: The problem is the Theme of the application. Try changing the theme to some darker theme like:

<style name="AppBaseTheme" parent="android:Theme.Black">

and it should solve your problem. I found this similar issue earlier and rectified this by changing the theme. But I didn't research much but I feel that this is Android issue and the bubble should try to change the text colour according to the theme.

Let me know if it solves your problem, or not.

Problem 2: The other issue you are talking about for not taking focus, you may consider the following link: Text Truncating and Focus Issue.

----------------------------------------Updated Answer---------------------------------------------

Q1) What should I add to the theme configuration in order for it to always work, no matter what theme I use? 

According to my findings here are some results:

[Note: Only applicable for devices running 3.0 and up]

If your build target is:

  • less than 11, then using

    parent="android:Theme.Light"    --> setError() message doesn't work or shows very faded text colour almost blending with color white
    parent="android:Theme"      --> setError() message works
    
  • greater than 11, then using

    parent="android:Theme.Holo.Light" --> setError() message works
    parent="android:Theme.Holo"       --> setError() message works
    

Since, your project is supported for devices less than 11 API level and you want to support 4.0 and plus too, your best bet would be to go and integrate HoloEverywhere in your project which will solve your problem and you will be able to use your ActionBarSherlock too, for compatibility, check this SO Post.

Q2) What are the available configurations for the error indication UI ?

Mostly you can customise drawables and icons but I doubt you will be able to configure your text and background(If anyone knows more may point out on this)

I would suggest you to check this SO Post for immediate answers.

And for placing the correct focus, for every validation checks, you may place this code:

EditText.setFocusableInTouchMode(true);
EditText.requestFocus();
EditText.setError("My Error Text");

Let me know for any issues.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top