Letter Spacing in EditText for Android - android

I am trying to have a custom EditText based on the background that i am using for. The Background image has some spaces between the entry areas so i need to have some space between the characters(kerning) to fit them right in. So for example after every character the user enters, i need to put 4 whitespace after that.
I couldn't find any solution for this on the net so far, some people suggested TextWatcher, but i couldn't manage to make it work as i want it too.
Can someone help me about it?
Thanks

I have you considered using a custom font? Some font types are made to stretch out or shrink or have empty spaces. With so many different fonts available online, you can definitely find something. You can also make your own with a software. It might be time consuming if you start the lettering from scratch. I'm not 100% sure if it'll fit exactly to your background, but it's idea that you can consider.
If it doesn't fit, I supposed you can always customized the background to fix your font too. Here's the code for those who might want to use custom fonts in their app too.
Typeface myfont = Typeface.createFromAsset(getAssets(),
"fonts/Blocks2.ttf");
myeditText.setTypeface(myfont);
The font is in the asset folder under another folder called fonts.

This question is related to How to change letter spacing in a Textview?
As shown at this issue: android format edittext to display spaces after every 4 characters a solution might be to insert spaces with Java code...
You need to use TextWatcher to achieve visual purpose spaces.
And use any simply split string by space logic to join it back or loop
through the entire string per character wise and eliminate (char) 32
from the string
As far as i know actual character spacing is not possible, though i'd love to use that myself as well.
Another option might be to use a custom font with the character spacing included.

Related

Is there a way to fix letter width in EditText?

I am trying to find a library or a simple trick to fix the width of each letter in an EditText so that the dashed lines on the background match exactly the number in the EditText. You can see the photo for the desired effect.
Using various widget i.e. Edittext in a row with the text style to underline will helps to get these type of design else i don't think there is any hard and fast rule or tricks.
There is no simple way of doing this, especially not when aligning to a given background, because many factors such as display size and density can change the relative positioning of the EditText. You could perhaps work around this limitation by drawing the white lines under each digit yourself, using a custom font or underlining and separating the digits with a space. See this question for a more detailed explanation on the limitations and possibile solutions concerning letter spacing.
I only know that, font monospace will be useful. Other fonts set different widths to each character.

Changing text's size according to TextView

Hi guys I've wondered if I could resize the TextView's text in order to make it fit withing the text view.
I want the text view to have a default text size, but in case the text is too long and requires more text than the TextView could offer, the text size should get smaller.
I've seen this answer which is awesome, but it's also from 2013, so I've wondered if there's a simpler way of doing this. Android keeps changing and evolving so I just wanted to make sure there's no easier solution first.
You can use AutoFitTextView for better result .
A TextView that automatically fit its font and line count based on its
available size and content.
There is no built-in way of achieving this in Android, so you'll have to resort to 3rd party classes and libraries to fix your problem (Like the one you linked)
I have tried a few different classes i found from googling around about 6 months ago, but i never found a 100% working solution, there were always some little kinks or flaws in my experience.

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.

How to set numbers as images on TextView?

I made a display, that will show the sum of purchase. It's a TextView with background image. I have a designed digits too. How can I set those digit images to that TextView or do I have to create some layout instead of simple TextView? If I need to create layout, can you add some code sample, how can I do it?
Here's an example what I want to achieve.
Regards,
evilone
As far as I know, your two options would be to create your own True/OpenTypeFont (setting the color of the text to yellow in xml most likely) or to code your own custom ViewGroup which will take a String and convert each character to the appropriate image.
If you're able to construct your own font, you can add a font folder inside your assets project folder, and put your font in it. It can then be loaded like this:
Typeface tf = Typeface.createFromAsset(myContext.getAssets(), "fonts/MyFont.ttf");
myTextView.setTypeface(tf);
This site has free fonts even for commercial use, http://www.fontsquirrel.com and I searched for led and found a font called radioland that looks good, though the numbers are at an angle. If you do use that site, I've found it's good to verify the font is indeed free to use with it's included license or a software and can open the font and view it's headers.
Install and use the National Instruments 7 Segment LED font. For the Pound symbol, you can make a tabular layout and put it in a corner.

Android TextView and how to determine the number of visible characters

How can I determine the number of visible characters that a TextView can display. For example if I change the orientation this number may change. If I change the resolution then also the number of visible characters changes.
Thanks in advance
Thank you for your answer.
Currently I am developing a small text based game to become acquainted with the Android API. For that reason I need to know exactly how much characters can be displayed in the visible area of a TextView widget. I saw an example of Paint but wanted to know if there are better solutions.
Ideally, you design your GUI such that it does not matter. For example, you can use android:ellipsize to deal with strings that are too long for the available space.
There are classes in the 2D drawing APIs (e.g., Paint) that seem to be tied into this, but it does not look like much fun.
You can use ellipsize property but there has been a bug that has been filed on the same
http://code.google.com/p/android/issues/detail?id=2254
On the bottom of this page you could find an alternate approach which can draw exactly the number of lines on a given space...

Categories

Resources