Android text style missing light, medium, thin, - android

When setting custom fonts for a textview, I can only choose normal, bold or italic:
How can I set the style to be light instead of bold in the following example?
<TextViewWithCustomFont
...
android:textStyle="bold"/>

This is font specific. Not all fonts have a light, medium, thin attribute/style, but the default font should. You can use the default light font by using fontFamily: sans-serif-light or for thin, fontFamily: sans-serif-thin.
For custom fonts, you would need to include the light version of the font and use it.

Letter Spacing
As an adjacent solution to change a font's looks, you could use letterSpacing. This will change the distance between the letters within a TextView.
A positive number like 0.2 will add more of a gap, while negative like -0.1 will squish the letters together.
In Android 21+ you can programmatically call setLetterSpacing or in XML add letterSpacing.

You can only combine those three attributes :
normal
bold
italic
http://developer.android.com/reference/android/widget/TextView.html#attr_android:textStyle
So it can be :
normal
bold
italic
bold | italic

Related

How to increase the PasswordField text when seen on a mobile device?

This JavaFX control doesn't seem to have a GluonFX equivalent for the mobile device environment. On the desktop, the circle char that masks user input looks fine. But on the Android the same char is as small as tapping paper with the tip of an ink pen.
I've tried
.password-field .text {
-fx-font-size: 15;
}
and
passwordField.setFont(new Font(15));
but neither seem to change it. Is this just how it is for now? No way to make those black circles look bigger on the phone to the User?
This doesn't work:
.password-field .text {
-fx-font-size: 15;
}
because the inner Text node has its font property bound to the TextField/PasswordField control, and when the latter is set, it overrules it.
However, as you mentioned, this doesn't work either:
passwordField.setFont(new Font(15));
If you use Gluon Mobile, the glisten.css stylesheet applies the Roboto font, and the password field gets Roboto, regular, 13.3pt.
You can verify this by adding a listener:
passworldField.fontProperty().addListener((obs, ov, nv) -> System.out.println("Font: " + nv));
which results in something like:
Font: Font[name=System Regular, family=System, style=Regular, size=15.0]
Font: Font[name=System Regular, family=System, style=Regular, size=13.300000190734863]
Font: Font[name=Roboto, family=Roboto, style=Regular, size=13.300000190734863]
So it ends up using the usual "small" font.
But this works:
.password-field {
-fx-font-size: 15pt;
}
as it is applied after the Roboto font is set (your css stylesheet is applied at the end).
Font: Font[name=System Regular, family=System, style=Regular, size=15.0]
...
Font: Font[name=Roboto, family=Roboto, style=Regular, size=19.999999523162843]
(Note that on Android there is some font scaling applied as well).
If the bullet symbol is still too small, you can use a bigger font size.
See https://www.htmlsymbols.xyz/unicode/U+2022): Only with 28+ you will get a more visible symbol.
The only caveat of using large font sizes is that the caret gets too tall.

Android Studio text font and density

How to make text bold in the android studio and also how to change the font style.
I added the font style in font folder and when I use it through android:fontfamily
it becomes somewhat distorted.
For Bold:
android:textStyle="bold"
For the font:
android:fontFamily="#font/yourfonthere"
For the blurryness I would try to scale the text size down a little bit
To change your text Style and your font in android, you have to add those two lines in your xml file.
android:textStyle="bold"
android:fontFamily="serif"

Issue with custom fonts in TextView and WebView

There is an issue with English text in TextView and WebView when using Arabic or Persian typeface, The following image is an example of Persian and English text in both TextView (2 views in the header) and WebView (at the bottom) when using default typeface : Shot 1
But when applying a custom typeface it looks like this (Iran Sans Serif is applied here but almost all Persian fonts have the same issue) : Shot 2
As you can see, in TextView with Persian typeface, English texts are not aligned correctly and in WebView there is extra padding between some lines due to difference between Persian texts size and English texts size.
Be sure that there is no problem with the fonts because in Websites, they're working like a charm!

Android "Roboto Light" pixelation

I'm including the Roboto family of fonts in my application, and create the fonts in code like so:
Typeface robotoLight = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
I have noticed that certain smaller sizes (even the suggested sizes from the Android Developer Typography page) appear distorted or pixelated. Here is a screenshot of a few TextViews in the app:
"Upcoming Dates" uses a larger size and looks fine. The other ones are sized at 14sp and look awful. The problem is not with margin or padding in the TextViews -- I've tried altering both. Does anyone know what causes this problem, and how to fix it?
Try the following on each of your TextViews with the custom typeface:
int flags = textView.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG
| Paint.ANTI_ALIAS_FLAG;
textView.setPaintFlags(flags);

my font size is 0 byte after launching the app

I have trouble with my font.
I need to display plain, bold and italic text in a specific font in the same textView.
I use html.fromHtml and with the regular android font it works fine.
I want helvetica instead, so I built a single font file witch contained the three fonts (plain bold italic), and used setTypeFace on my textView. I built it from 3 otf files with fontBuilder.
But when I call Typeface.createFromAsset(getAssets(), "fonts/HelveticaNeue.dfont");
i saw that my font file size was 0 bytes, and indeed in my project I can't import it well,
when i go in the folder fonts i see that the size is ok, but from eclipse point of view, 0 bytes.
Does somebody have an idea ?
ANSWER:
The problem was that my font didn't had dataFork, it's a thing that you have to add to your font for it to be understood by PC's, and Unix OS.
is it correct format .dfont
i think fonts should be with .ttf
Typeface.createFromAsset(getAssets(), "fonts/HelveticaNeue.ttf")

Categories

Resources