EditText align digits to background image - android

I have an EditText using the image below as the background image.
The EditText is numeric only, and is limited to 6 digits long. On some devices, the digits line up perfectly in each slot, however I can not find a way to make it consistent across devices. On larger screen and high density devices, the digits do not line up, and end of being in the middle of a divider. The layout that contains the EditText is using a Weight attribute to allow it to scale correctly across devices. Can anyone suggest a method I can use to make the digits always line up in the slots of the background image - regardless of the screen size/density?
Any suggestions/examples would be GREATLY appreciated!!!
Thank you!

Use 6 different EditText views with each view containing only one digit. When user input some value in first view just change the focus to the second one to make typing the values easy.
You can also handle backspace button to taking focus back to views before.
You could use TextWatcher for listen inputing events on each EditText

Related

how to retain consistent spacing between characters when toggling from inputType numberPassword to showing numbers

after setting my edittext's inputtype to numberpassword and following this fantastic post EditText view with keyboard number only , I'm finding that the bullets when in password form take up considerably less space than the numbers they transform from and to. I was wondering how to fix this such that the bullets take up the same x-space as the numbers do.

Blur input on edittext

I am creating an app for users to hold the phone in a specific way - therefore one method i am testing is blurring an image depending on the phones position.
Now I want to let the user do a small task - write something to an Edittext and blur the text too --- sure I could display the textinput as textview on top of the image, but probably the users eyes are focused to the edittext and not the image/textview
So is there a possibility to blur the input within the edittext? An other possiblity would be to blur the complete view (combined with a lot of refactoring), but I would prefer the edittext solution..
Would be great if someone would be able to help me!
You can try and use the alpha property of it to reduce the opacity.
A similar answer that makes a custom TextView for it can also be seen here: https://stackoverflow.com/a/2904259/8118133
You can also look at adding a BlurMaskFilter if that does the job for you.

Prevent EditText from allowing more characters to be typed out based on rendering of Fonts

I have an item in a RecyclerView that gets rendered based on whether or not it has multiple words in it. If the item has multiple words, I assign a smaller typeface, if not then I assign a different typeface with a larger textsize.
Problem:
I want the EditText to detect if the rendering for any given TypeFace is going to exceed a certain amount, if so then prevent the user from typing out anymore characters.
Smaller TypeFace:
If the rendering exceeds 3 lines, do not let the user type in anymore characters
Larger TypeFace:
If the rendering exceeds 1 line, do not let the user type in anymore characters.
Sample Drawing (Just to be clear the EditText is not inside this layout):
Smaller TypeFace
Larger TypeFace
Initial Hunch:
I am thinking that I create a custom EditText class and in that class get the TypeFace determine which kind it is and try to pre-render it. If the rendering exceeds the restrictions prevent anymore characters from being typed out.
Any thoughts on this?
Any ideas for implementation?
Edit: I have a solution will be posting it up shortly

Android: Way to set physical length of edit text field

Is there a way to limit the input length of a Android edit text field using some sort of physical parameters (i.e. inches, pixels, etc.) I do not want to limit the field by character number.
Thanks for the help!
you can use android:maxWidth="100dp" but that is going to set the max width of the View itself, and will not affect how many characters are allowed to be typed into it.
I do not beleive there is an easy way to accomplish what you want. The only thing I can think of is use a TextWatcher and dynamically determine how many characters will fit in the the size that you are wanting (which will be different for different devices). That is still basically "limiting the field by character number" though which you state you don't want to do.
Can you elaborate on why you are wanting to do this? Perhaps there is a better way to solve the overall challenge that you are facing.
You want to add a text changed listener (TextWatcher). In your listener you'll need to measure the size of the font, and the pixel density of the screen, and the number of characters. Multiply all of those together and you should know how physically long the text is (with a few caveats).
Having said that, this seems like a weird restriction and I'm not sure why you want this. Every device is going to have a different screen size, so measuring your interface in inches is typically a bad idea.
You could find how how many M's will fit in the printed form and then use EditText.SetMaxEms To make sure the input will be printable on the form.
Try this on your EditText
android:maxLength="10"

Android. Image in EditText

I wanna create a simple calculator. One from my goals its place in EditText field images with special math chars as like square root, pi... F.e. :
2/34*sqrt(121)
Here I want to place images instead of divide, multiply chars, sqrt string.
how I can do it?
Some more questions:
Does it actually need to be Editable i.e. user can type directly into it? If so how will it work? when they type '*' it will realize it and replace it with your png? Would it be acceptable if it didn't interrupt as they type but instead all at once when they are finished entering the entire line?
Best answer I have for now:
EditText doesn't support that by default. You'll likely have to create your own view that is some kind of mashup of EditText and LinearLayout that can hold ImageViews with your pngs. If it doesn't need to be editable by the user it is going to be easier because you can make your custom view a LinearLayout and add TextView's and ImageViews with the proper text and images set in them. If it does need to be editable it is going to a bigger challenge. You'll have to use a TextChangedListener to pull out each character as it is typed and replace it with an ImageView if need be. Seems to me like the hard part is going to be knowing where to position the ImageView and having the EditText know that you want it to pick back up with text on the other side of the Image. Im not sure how you'd go about that. Maybe the best solution is you have an EditText that they type into and then seperately you have your custom view as a display view. That way you don't have to worry about positioning images over the top of an EditText and correctly moving the cursor to right side of the image.
What I would suggest is looking into a freely available font that includes mathematical symbols (some quick searching turned up the StixFont project), then just add that font to your assets, and set it as your typeface. You'll still probably need a TextWatcher/TextChangedListener as Tim suggested (unless you're using your own keyboard to input the symbols) but this would get around the problem of trying to insert images into a text field, and would also keep the vector quality provided by fonts versus a raster image embedded into a text field.

Categories

Resources