Error indicators (for form validation) not shown for Android 4.2?

Background

On Android, you can set an error indication for any kind of EditText if you want to show the user that what is entered there (or not printed) is incorrect (the so-called "form checks").

There is a good library for this ( here ), and there are a lot of posts on how to use it.

Everything worked fine for me until I ran it on Nexus 4 with Android 4.2.

Problem

Sometimes it just does not display error icons. In that case, only when I give the focus to the editText (which has the problem) does it show the bubble, but it is empty and does not show the error icon.

In addition, in all cases, the bubbles are always empty.

Why is this happening, and how can I fix it?

Note. I use the actionBarSherlock library, so I need to use their themes or a theme based on them.


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 finally realized when this error occurs: if the focus is on another editText that does not have an error, and the verification error is on another editText, the indicator does not appear until until the text editing is focused.

+4
source share
1 answer

Problem 1: The problem lies in the theme of the application . Try changing the theme to a darker theme, for example:

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

and he should solve your problem. I found this similar problem before and fixed it by changing the subject. But I didn’t understand much, but I feel that this is a problem with Android, and the bubble should try to change the text color according to the theme.

Let me know if it solves your problem or not.

Problem 2: Another problem you are talking about, because it does not focus, you can consider the following link: Truncation of the text and the problem with focus .

---------------------------------------- Updated answer-- ------ ------------------------------------- p>

 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 conclusions, here are some results:

[ Note: only applicable for devices running 3.0 and above]

If your build target:

  • 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 with an API level of less than 11, and you also want to support 4.0 and plus, it is best to go and integrate HoloEverywhere in your project, which will solve your problem, and you can also use your ActionBarSherlock to ensure compatibility, check the SO Post .

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

Basically you can customize drawings and icons, but I doubt you can customize your text and background (if anyone else can point this out)

I suggest you check out this SO Post for immediate answers.

And to place the correct focus, for each validation check, you can put this code:

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

Let me know of any issues.

+4
source

Source: https://habr.com/ru/post/1484571/


All Articles