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"
Related
Everything in the app looks fine until the font size is increased in the settings page on Android phones.
Image of Text Before Font Size Change
But as soon as the font size is increased in settings, the text overlaps each line.
Image of Text After Font Size Change
Here's the code for the TextView
<TextView
android:id="#+id/song_lyrics"
android:textSize="14sp"
android:minHeight="32dp"
android:textColor="#color/black"
android:lineSpacingMultiplier="1.2"
android:letterSpacing=".06"
android:textStyle="normal"
android:layout_marginTop="24dp"
android:layout_marginRight="24dp"
android:layout_marginLeft="24dp"
android:layout_marginBottom="24dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineHeight="16dp"
android:text="Abraham’s blessings are mine (bis) \nI am blessed in the morning, \nI am blessed in the evening,\nAbraham’s blessings are mine."/>
The error was in my code, I tried to use both the android:lineHeight attribute and the android:lineSpacingMultiplier attribute.
Don't use lineHeight for this type of problem, use lineSpacingMultipler or lineSpacingExtra.
Lesson learned :)
I am making Game with android studio everything is completed but only one issue i have. Text size's not changed. How to make it for auto fit on any screen like phones and tablets.
Try this Demo Git Project Android-autofittextview.It may help you.In your layout add like this to mention size android:textSize="#dimen/_15sdp".
you can use this library
to auto fit your text depend on TextView width.
also you need to set android:textSize in dimens.xml like this:
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/textsize"/>
for have different size for different devices just define dimens.xml for different screen size (for example: Value-large)
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
Previously, to make my app workable in Gingerbread device and above, I have to copy the Robotto font resource into asset folder. This is because Gingerbread doesn't come with Robotto font itself.
However, let say, I decide to deploy my app to Jelly Bean device only.
Do I still need to copy font resources into my asset folder manually? Can I use font resources from system itself? Is it something encourage-able? I was thinking, without supplying my own font files, I can make my app smaller.
This is the code to get TypeFace from asset folder.
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
If I want to get TypeFace directly from system itself, how?
The good news is, if you're supporting 4.1, it's dead simple. Check out this link and scroll down to fonts for the full details, but basically, you'll have three font families (Roboto, Roboto Light, RobotoCondensed) to choose from, and four styles for each (normal, bold, italic, bold italic).
In XML, you can just use the standard text attributes:
android:fontFamily="sans-serif"
android:fontFamily="sans-serif-light"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"
android:textStyle="italic"
android:textStyle="bold|italic"
Or programatically you can acquire them like so:
Typeface robotoLightItalic = Typeface.create("sans-serif-light", Typeface.ITALIC);
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")