I am working with 4.0+ EditText and have to perform validations on a bunch of fields. When a validation fails, I have to change the color of the EditText to red and display a message. Now, I have easily customized the EditText using style and theme, but there is no state for error which I can use in the state list drawable. Any ideas on how this can be achieved?
Why not use EditText.setError(CharSequence error)
The result will look like this
I got it working using LevelListDrawables
Related
I'm trying to create a search bar like.
I have to use a particular autofill, infact I can't use a dropdowns menu.
For example if I write Noce the edittext will have to suggest Nocera in the same editText, like this.
but if the user write something else the pointer have to the end of the typed text (in this case Noce) and the hint have to disappear.
Is there some library that allows me this?
Thanks for the help.
There's this library that will fulfill some of your requirement called Auto Fill EditText
Finally I have solved this using two EditText in the same position. The first one is a normal editable EditText, the second one is not editable from the user but is used to show the hints programmatically.
I am having an edittext and an icon. Clicking on this icon I show DateTime Picker. I have set setFocusable(false); and using setError on this edittext. But when any error occurs only icon is getting shown. Text is not getting shown at all. I have tried _input.setFocusableInTouchMode(true); also but it gives users to enter any text in this edittext which I do not want as I have created this edittext for date time only.
So, how can I show the error message then, can someone please help me.
Thanks a lot in advanced.
Add following lines to your code:
et.setFocusable(true);
et.setFocusableInTouchMode(true);
et.requestFocus();
Why do you use an edittext, if you do not want the user to input text? you can use a textView and textView.setText("your time") instead.
You use like this if you want to set Error on your edittext with icon
ed_emailId.setError("your Error message",R.drawable.ic_profile);
and if you want to set only error and icon will default then use like
ed_emailId.setError("your Error message");
i hope this will help you
I am working on a spinner in which I am getting values of the spinner from the database.
I want to add hint to this spinner...and the problem arising is that I cannot able to add hint to this spinner.
What should I do?...
You have to create a costum adapter for your spinner. There are some tutorials on the web:
Android: Spinner hint
I think you are trying to make an initial text in spinner. You can do it in many ways
How to make an Android Spinner with initial text “Select One”
Otherwise you can use a button instead of spinner and create a dialog when button clicked
I have developed a little component to get this. Just add a hint text in AutoCompleteTexview and build CompleteSpinner with it
https://github.com/FernandoGaliay/CompleteSpinner
I'm developing a APP for Android for educational purposes, and I see this in Linkedin APP. I like it!
Is a eye, and function is similar to CheckBox.
How I can do this?
Is a customized EditText?
Is a customized CheckBox inside EditText?
The password box is probably a Horizontal Linear Layout with a background border surrounding it. For the edittext, it seems like a custom styled one, you can look here to figure out how to implement one.
Edit:
As for the checkbox, look here
just pass null to setTransformationMethod to show the password like --->
yourEditText.setTransformationMethod(null);
On ICS, when using a theme based upon android:Theme.Light the text in the error popup when using setError(...) is white, as is the background.
I can fix this issue by adding <item name="android:textColorPrimaryInverse">#ff000000</item> to my theme. While this helps I'm a bit worried that by doing that change some other text, that uses textColorPrimaryInverse will turn from white to black and perhaps not be visible. I would rather just change that attribute for the EditText that displays the popup in question or for just that activity.
Clarification
I would like to change a property, preferably the text color, of the popup that displays the error message when the user enters something wrong into an EditText.
You can do it like this:
editText.setError(Html.fromHtml("<font color='red'>Error Message!</font>"));
In code use http://developer.android.com/reference/android/view/View.html#setBackgroundResource(int) or http://developer.android.com/reference/android/view/View.html#setBackgroundColor(int). They belong to View, but EditText inherits them. The second methiod is easier, the first is more consistant.
Edit: Oh, it is a more hard question.
Maybe, using EditText.setError(CharSequence error, Drawable icon) you can put error text on the icon? You can set setBounds(Rect) for the icon, so, it could be enough big. The icon can be the color you need.
But I use onKey,beforeTextChanged, onTextChanged and show my own error message as a Toast. For the toast you can use an usual View.