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.
The new Autosizing TextViews are pretty awesome, but it seems a fundamental thing is missing: ellipses.
Adding ellipses still requires defining the maxLines attribute, but if I want to be able to dynamically resize the text size according to the text view boundaries, I'd also like to be able to dynamically add ellipses when needed. Right now, if the text doesn't fit even with the minimum text size, it just gets cropped.
How could I add support for dynamic ellipses without giving up the new autosizing support?
The best solution I came up with so far was to programmatically set the maxLines to the proper value on runtime. Something like this will get the job done:
fun TextView.setMaxLinesForEllipsizing() = doOnPreDraw {
val numberOfCompletelyVisibleLines = (measuredHeight - paddingTop - paddingBottom) / lineHeight
maxLines = numberOfCompletelyVisibleLines
}
Be aware that this depends on Android KTX (but can also be easily achieved with a regular OnPreDrawListener).
Then we can simply call this extension from any TextView we want to get the dynamic ellipsis.
textView.setMaxLinesForEllipsizing()
If the text changes it might be necessary to call it again, though. So it might also possible to reach a more complete (and complicated) solution by moving this logic to a custom TextView and maybe overriding onTextChanged() there.
I've been following the Google official Material Design guidelines (http://www.google.com/design/spec/style/typography.html) on typography but I find them to be quite lacking. For instance, they list 10 styles you should use for things like body, subhead, title, headline display1, display2, etc. type text in your app... This leads me to the first problem.
Problem #1: How does one know what a "subhead" is, or a "title" vs "headline", or when should "display1" be used as opposed to "display4", are there standards for these items?
Moreover, the guidelines state that leading space should be built into the line-height of the text. Therefore, problem 2.
Problem 2#: How can I add "leading" space for text in Android, is this relevant Android guidance?
Problem #3: Although I've downloaded the latest version of Roboto, my medium fonts look absolutely bold, as opposed to Google's elegant and slightly thicker medium fonts, how can I confirm my font is actually different than Googles?
Thank you very much
"Show me the code": not mine, but see comment below for one option, and also how Plaid app (Butcher) tacked typography challenges by visiting its source on Github (BaselineGridTextView class).
Disclaimer: I'm by no means a reference in this subject, but your question is a month old without any answers, even though it is important and its importance will only grow from now on. That said, I'll try to, at least, give some light and offer my head because of the possible mistakes.
Problem #1: How does one know what a "subhead" is, or a "title" vs "headline", or when should "display1" be used as opposed to "display4", are there standards for these items?
These are common, standardized, abstract text entities that came to us from the traditions in printed publishing.
Display: big text, normally used at placards, attractive slogans, things that demand and compete for attention, that should draw attention when the user isn't looking. It is less readable exactly because it should be very short (draw attention at once, not part of extensive flow). I imagine the 4 different display sizes in Material Design is just extra care from Matias and his team, but I doubt apps will ever use more than 1 display size (maybe magazines and rich media app, perhaps). Most apps won't even use display size at all.
Headline: traditionally, I believe, if my shallow understanding of this subject is right, headline sizes are used as short taglines of the story. Not a description, just a tagline, a short message. An example of a headline: ASSASSIN KILLS KENNEDY. In common apps following Material Design, it is used as the main subject of a screen (just like pages of a newspaper). I think (as in not sure) that this may be called “Heading” elsewhere.
Title: honestly, it is very generic, and because of its modest size (compared to headline and display), it is one of the styles I use the most: it is very useful in places above a block of text. For example, “Eula” as a title for the eula text that follows this title, or “Authors” immediately before a list of authors. It is widely used in the framework as well.
Subhead: this is more specific. It is an immediate, inferior degree to “headline”, and is used to provide excerpts, quotes or a brief description of the text block that follows it. Example of a subhead (following the headline example): Governor of Texas Wounded, Marxist accused of murder. In Material Design, because of the size, the most common place I've seen it used in is in a two item list item, exactly because it is used as excerpt of an email (to provide an overview) or as a phone number (a detail of the most important asset for a particular person in a phone list).
Body: main text. Pretty obvious. The most readable of them all, and the only option for long texts.
Caption: footnotes and small text. In print, it is widely used as captions of images. In Holo, I think (as in not sure) it was used as divider text (but in all caps). In Material Design, I think dividers stopped using caption text and use “body” with light color.
Other programs use these (part, or all) concepts themselves with slightly variations:
text styles of text processors;
font settings in image software like Photoshop, Illustrator and so on.
optical sizing of fonts. Adobe, for example, uses “caption”, “regular”, “subhead” and “display”, which, as you can see, is meant to complement sizing and leading with font shapes especially tailored to different size spans;
The general concept seems to be that these are abstract entities that represent gradients of importance in text sets, and may have flexible rules between publications as long as it is used consistently within a publication, theme, application etc..
Problem 2#: How can I add "leading" space for text in Android,
This is for those places where you mix TextViews with different styles, like in the image example (or with text spans, of course).
Let me be honest: right now, for emergency purposes, I'm using my eyes with superimposed grids to check my leading. I'm starting with the leading size, then I subtract the font size of the following text line and some small amount as the descender of the current line. Then I make tiny small optical adjustments if needed. It would be nice if these elements (x-height, cap height, descender etc.) could be calculated exactly, but I honestly didn't dive into this yet (but it's probably possible). I'm satisfied with my “eyeometer” while I don't perfect MD in my layouts.
However, and I just looked at this (didn't try it out), I believe you can dive into FontMetrics, measuring the fields and applying the proper dimensions on the fly between the two TextViews shown above. I'd try that first (ascent of the next and descent of the previous).
is this relevant Android guidance?
Yes, it is. Very much. Place a text below another, when they have different styles. Like a title followed by a body, and try to just take a wild guess: it won't work and your app won't be consistent with the system. See above.
Problem #3: Although I've downloaded the latest version of Roboto, my medium fonts look absolutely bold, as opposed to Google's elegant and slightly thicker medium fonts, how can I confirm my font is actually different than Googles?
Please tell us where exactly you're getting the two samples to compare. Font rendering may be affect by many different things, and each system uses its own hinting algorithms, besides many other things. There are slight variations even between different Roboto versions and different Android versions. Surely medium looks “boldy” compared to regular, but not actually bold.
You can check the fonts in your sdk/platforms/android-APIVERSION/data/fonts folder. Rendering with Ubuntu 15.04 (slight hinting), out of the box, as of android-22:
I think it stays accordingly to the sample.
To compare with something also widely available, this is (part of) the Ubuntu font family (regular, medium and bold, respectively). In my opinion, medium also comes closer to bold than regular:
Minion Pro (regular, medium, semi and bold). It is more evenly weighted possibly because it also offers a semibold variant, but we are talking about a serif font made for fine print and with much more time in the market to have been continuously refined:
I hope this helps.
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.
I am trying to make a fraction:
I am using this is a text view but it is not rendering very nicely:
"5"+'\u2044'+"9";
It does not turn the text into a nice fraction instead it sort of covers part of the numbers and squishes them together.
Any solutions or alternatives?
Try:
tv.setText(Html.fromHtml("<sup>5</sup>/<sub>9</sub>"));
Don't know if that will look good, but it's worth a shot. Otherwise, other than the single-glyph fractions like 1/2, I suspect you either will need to go without or render it yourself.