I have an EditText field and the user may only input six digits. When the EditText is focused, it should hint the user that he can only input six digits.
The idea is to display the remaining digits in gray, like this:
When the user inputs a digit, then it appears like this:
(The red vertical bar represents the cursor.)
The cursor should not be positioned behind its current position in both images; the gray digits should only be visible, and should not be selectable.
So in fact I want to set a placeholder text, but retain a part of the placeholder text whilst the user is typing.
I read about the TextInputLayout class from the Design Support library, but I don't know how I can achieve abovementioned idea.
How to do this?
I will give you only the idea, so implementation is up to you. Create your TextWatcher, in
onTextChanged()
Count how many digits user wrote and depending on this number create string padded with zeros. After it, make zeros be of different color
Spannable textWithTintedZeros = new SpannableString(paddedString);
textWithTintedZeros.setSpan(new ForegroundColorSpan(yourGrey), firstZeroIndex, length, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
editText.setText(textWithTintedZeros);
And at last set selection to be before zeros with
editText.setSelection(indexBeforeFirstZero);
Don't forget also to block changing cursor position. I think can be done with
View.OnKeyListener
You could add over the edittext a TextView with gravity right. Then in the listener of edittext (ontextchanged) modify that TextView.
I don't know if you can do it with only EditText.
Related
I'm creating a PIN dialog that contains multiple EditText. The behavior I want to achieve is, when the user enter a character, it gets to be shown first before being masked with EditText's password character (bullet/dot).
Instead of managing the multiple EditText, I have a hidden view (EditText) that handles the keyboard input. It's text will then be set to the other EditText that serves as the pin view. However, when I set the value for the pin from the hidden view, the password character is being set right away, no more preview of the set value. The behavior is different when I tried to enter a character directly to the pin view.
How can I achieve the behavior I want with the this current setup? Thanks!
You Can also Achieve This behavior By just using one Editext.
On User Keypress show Current Character for 1 second while all entered characters are shown * if entered.Then replace all text with *,with the length of Text enter inside Edittext.
Basically Toggling The Visible Character with * after 1 second while holding real password inside a variable and then hiding newly entered character by replacing Edittext text with * of variable.length.
I believe what I wanted isn't possible. From what I'm doing the cursor moves to the next EditText when the current received a value.
Using an EditText with inputType (in my case) numberPassword, as soon as the focus was removed from the EditText or if it doesn't have the focus in the first place, setting a value to it will immediately show the 'password' character.
I have two edittext fields. What I want is, when the user types something in second text field, the underlines of both the fields should highlight with the same color.
In the above picture, there are two edittext fields, one for country code and one for mobile no. As you can see, only one field is highlighted, I want both of them highlighted and cursor should remain in the mobile no. field.
You can create a custom view, contains EditText and an underline. EditText has no background, and you can use an ImageView (or a view with right color) as the underline.
I have a TextView and number buttons to type inside the TextView like a calculator.
I need to keep the cursor to stay in its place when I am typing the numbers and NOT to move.
For example lets say this is the cursor "[" , so this is what's happening now:
[12345
What I want when I am typing the numbers
12345[
This numbers are just an example, what is important for me is the cursor stay at the right and not to move.
Update:
[12345 the first number what I typed is 5 and the last one is 1.
For EditText you can change the cursor for the view. If you are currently manipulating the cursor position in your TextView, then you can do something similar in the code if need be. There might be an automated way to do so, but I had thought setting the gravity as others had mentioned would do the trick.
EditText editText = (EditText)findViewById(R.id.calculatorEditTextView);
editText.setSelection(editText.getText().length());
I am setting a text in textview.And it is marquee text.Not just the text, it is an array of text concatenated one after another and added to textview.I want that if i will click any text then that text(or word) will be shown in a dialog box.First of all is it Possible anyhow.I tried to use Spannable from this link first answer.but it's not working as per my requirement as i have marqueeing text.
Why wouldn't you replace the marque with something more useful? :) You may wrap your textView into a horizontal scroll view. Then you have a thread (AsyncTask) that scrolls the text, using ScrollView.setScrollX() just as marquee does.
Can you guess, what comes next? Use spans, as suggested by the link, you quoted!
Hi I have a view with a TextView and linear layout. Linear layout is a kind of custom keyboard with number of buttons. So every button click I have to do some validations and append a character to the TextView.
Click of each button I append the character to the textview. Now when I turn the Accessibility feature ON, it is expected to read out the last character that is entered. But what happens is every time I set text in the text view.. Accesibilty feature reads out the 1st char in the textview, not the last char..
so Im confused on how to control the accessiblity of textview.. Can anyone plz tell me how to control the accessibilty.
You could use the setContentDescription() on your TextView to set it to the character you just entered. Then when accessibility kicks in it will ask your TextView for its content description and it should work. See docs here:
https://developer.android.com/reference/android/view/View.html#setContentDescription(java.lang.CharSequence)