This is a simple Android question that is hard to explain.
For an EditText field, I need 18 characters.
I limited the lenght of the edittext now with android:maxLength="18"
What I really need to do is show a dot for each character, or something like a placeholder for each character. I know you can use a real placeholder in Android, but it disappears when you start to enter your text.
Do you guys know any library or other solution for this?
UPDATE: I rather not use 18 seperate edittexts. That would be a lot of hassle to use a textwatcher on each EditText etc..
After trying out your suggestions, I found a solution of my own.
I placed two editTexts on top of each other, set the text of the top editText to 18 dots(.) and enabled to false (to get the greyish look).
I left the other editText untouched.
In code I set both the typeFaces to monospace, to each character would have the same size.
The output is an editText with a grey dot for every character, exactly what I wanted.
Thanks for the help guys, I appreciate it!
Related
I'm building am app that will allow Odometer entry. I would like to use the image shown below as the background on an EditText. Doing that is no problem, however I can not seem to get the digits entered into the text view to line up in the spaces of the image. I've tried adjusted the text size, font face, etc.
Here is the image I would like to use...
Does anyone have any suggestions on how I can accomplish this? So that when the user entered digits into the EditText, each digit goes into the correct "slot"?
thank you!!!
You can use android:letterSpacing? (only applies api 21 and over)
Set up 6 separate EditTexts on top of that image each with dimensions of the square they need to go into. Then set up event handlers so that it appears to be one fluid motion across EditTexts when the user enters data. Not very elegant but it'll work.
This may be a mundane question but I wanted to confirm if displaying the text of a button in capitals (like 'OK' or 'REGISTER') is acceptable or should it be in regular text (like 'Ok' or 'Register').
Thanks in advance.
P.S
I don't want to be seeminlgly shout at people using caps in buttons :)
In the Android Design site, you can see some examples of text under Writing Style which have just the first letter capitalized. "OK" is a bit of a special case though as it's an abbreviation of sorts, so I'd leave that with both letters capitalized.
The Android design guide details that and a lot more in the writing style page. Do not use all caps...
There's no standard, at least for buttons and labels it seems to be more of a "design choice". In ICS some of the text (e.g. preference and tab labels) are shown all in CAPS. Interestingly enough, there's a setting for textviews to accomplish that: android:textAllCaps. See this. If it's a block of text of course, don't do it.
Sure. You can use the Java String function toUpperCase() or toLowerCase()
Is there a way to represent special HTML characters in a EditText in Android? I want to display symbols like section signs (§), bullet points (), degrees (°), etc.
Is there a way to do this?
Thanks!
EDIT: The original post had asked about a TextView, but my intended question is about EditTexts. I want the user to be able to press the button corresponding to the symbol they want, and the symbol will be added to the EditText, and they then resume typing.
Have you tried \u00A7 \u2022 and \u00B0 in setText?
That are unicode numbers of those characters.
For EditText, you just have to create buttons with mEditText.getText().append(character) and probably mEditText.focus().
Have you looked at the Html.fromHtml(...) methods?
Alternatively you could just use a WebView instead of a TextView and use loadData(...) to load an HTML string.
I'm looking for a way to have a grayed out text as prefix in an EditText. This text should be not selectable.
It's a bit like the To field when you're composing a message with Gmail. The only (visual) difference is that this text disappears when you start typing.
Is there any trick to achieve this in Android?
Thanks!
You can use an image of the part "EUR 2500". this you can display in your editbox without affecting the rest of the part. Follow the code:
Drawable editTextDrawable = context.getResources().getDrawable(imageId);
editTextDrawable.setBounds(0, 0, editTextDrawable.getIntrinsicWidth(),
editTextDrawable.getIntrinsicHeight());
The drawable can be used inside the edittext as follows:
editTxtItemName.setCompoundDrawables(,
ListViewConstants.editTextDrawable, null, null, null);
As an ultimate solution, you can rewrite the full EditText class by extending it and modifying it in a way that it has a custom Background set by you, and a predefined padding set by you.
Put the EUR as the background, positioning it in the left side, and then give the starting padding of the EditText in such a way that the text the user types, starts right after the EUR text.
This maybe regarded as an overkill or a poor-man's solution to this problem, but still its the ultimate option. Not the smartest one perhaps, and I also don't know if its gonna work for sure :P
All the best!
I'm trying to make iPhone-style EditText element on android.
The one that will have an additional clear button appear on the right after text input.
Adding a new button is not a problem, but I'm a bit stuck with another thing.
A button occupies some space on the right part of EditText, and now characters display beneath the button. How to change maximum shown length of input for EditText?
I want EditText width to be N pixels, and editable area to be N-M pixels.
EditText.setWidth changes width for whole edit box.
EditText.setEllipsize should be the proper solution, but docs are empty, and as I see it truncates text based on some String value.
Applying a LengthFilter cut's the input length to number of characters.
Thanks in advance.
I suspect that android:drawableRight will save you a lot of pain.
Seems I've found a solution.
EditText.setPadding(l,t,r,b) seems to work fine, applying only for editable area
Try this : http://mytechead.wordpress.com/2012/02/07/create-ios-like-cleartextbutton-in-android/
This is a very old question, but thought I'd add my two cents for kicks. I'd probably use a 9 patch for this and set the content area to stop the text before it hits the button area.
This would require creating a custom view so that you can add a button in the desired position using relative layout so that it can be clicked to clear the edittext.
Alternatively you can use the compound drawables, but you would need to implement something like this
Handling click events on a drawable within an EditText so that you can handle the click events. Keep in mind that I doubt the button states (eg the down state) will work using this method.