Json array will contain list of string data. Each elements of the JsonArray in different language.How to find that language and set fontface in android.
For example ["tamil-font data","english - font - data","Hindi data"] like this.
About finding the language, I would recommend to add an indicator to the JSON.
About font face, make sure you have all font that you need:
2.1 Place the font to assets folder.
2.2 Any View that inherits from TextView can change its font, for example:
Typeface face = Typeface.createFromAsset(getAssets(),"fonts/epimodem.ttf");
tv.setTypeface(face);
2.3 if you need to change the text style linke bold or italic use in the TextView's XML attribute:
android:textStyle="italic" android:typeface="serif"
Tip: If need the same font more than one one time, reuse the Typface variable to avoid overhead.
Related
I read on Stack Overflow how to create a custom bold font and a regular one:
How to create custom font family with bold font
But I'm struggling to understand how to implement this in my strings. Ordinarily you simply use <b></b> to make text bold, but this doesn't seem to work with my custom fonts. All the text remains the same.
I know that you have tried adding the bolded font to a font family, but it hasn't worked. You can try one of the ways below. It will work even if you do import a TTF font.
One way you can do it is in strings.xml
You can create a new string and then add the b to bold it like this:
<string name="my_string"><b> My String</b></string>
You will need to create one for each string that you want to bold.
Then in your layout file, you can set the android:text to one of the strings from strings.xml and you can set the android:fontFamilyto the TTF font.
You can also bold it programmatically using the SpannableString in Java. Check this article to see how to bold programmatically.
Hope it helps!
I have 3 text views.
I need to set their weight as Light, Regular and Condensed.
Can someone help me on how to achieve this in Android?
Use android:textStyle on a TextView to set the text style like bold, italic or normal.
Here is an example of a TextView with a bold text style:
<TextView
android:id="#+id/hello_world"
android:text="hello world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"/>
If you want to use light or condensed, you will have to change your font. You can do it like this:
android:fontFamily="sans-serif-light"
For more information about fonts, please also look at the following answer Valid values for android:fontFamily and what they map to?
You can only show a TextView as Light, Regular and Condensed if the font that you're referencing allows those styles.
For example, if you import a font into your project and it doesn't have Light or Condensed, I don't think it's (dare I say) possible to make the text appear with that style in your TextView. If you are importing your own font, work with it programmatically e.g. In your activity declare a global TextView:
private TextView tv;
Then in onCreate(), reference the fontfile you save in /assets:
Typeface someFontName-condensed = Typeface.createFromAsset(getAssets(), "assets/NameOfFont-condensed.ttf");
tv = (TextView) findViewById(R.id.myTextViewId);
tv.setTypeface(someFontName-condensed);
Notice that I imported the condensed version of my font file (as .ttf), not as a packaged font .ttc. You can bring in various style versions of a font, but you should bring them in as individual .ttf files instead of one packaged file because you will want to reference the specific style .ttf.
However, if you're using a system font that allows you to reference various styles from your xml, see what they say here:
Valid values for android:fontFamily and what they map to?
As they say, for something like Roboto, you'll use the fontFamily.
I'm using Fontinator library for custom fonts in android. The documentation says:
use splited fonts without android:textStyle!
But if I want to make text bold, how it can be done?
Thanks.
Splited fonts mean a font with multiple files like this:
My-font-bold.otf
My-font-regular.otf
For Bold TextViews you have to use My-font-bold.otf and at normal TextViews My-font-regular.otf
If you have only one font file you can use textStyle!
I have a TextView which contains just one letter. The size of the text is calibrated so that the letter occupies entire TextView area. Now one of my users reported a problem that the letter does not fit properly into the TextView. From the attached screenshot I can see that she uses some kind of custom font on her Samsung S4 device. I am sure that's the problem. Here are some snapshots:
Custom font in a TextView over ImageView:
Custom font in the Status Bar:
Distorted letter N in my TextView:
Is there any way to make a TextView use standard android font ignoring any custom fonts that users applies? How can I install custom fonts on the emulator or Sony phone (do not have Samsung) and replicate the behavior?
Yes you can set custom fonts to your app. Make use TypeFace class.
Create a folder called fonts under assets folder and place all your fonts in it (Font format ttc or ttf. Folder name can be anything)
Within you onCreate method add the below code.
TextView mytextview= (TextView) findViewById(R.id.text_view_id);
// Loading Font Face. Replace with your font file name
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/your_custom_font.ttf");
// Applying font
mytextview.setTypeface(tf);
Similar way you can have as many as TypeFace you require and also use the same TypeFace declared on as many as TextView you want.
This tutorial below very well explains your requirement and also provides screenshot for better assistance.
http://www.androidhive.info/2012/02/android-using-external-fonts/
Also kindly note that TypeFace has a lot of other options that you can play around with. You can refer the android docs to get an idea about them.
I hope it helped you.
Thanks!!
My advise:
Create a subfolder in your asset folder called fonts.
Put there the fonts you want to use (for example ttc, or ttf) Set
your TextView typeface. For example:
yourTextView.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/yourFont.ttc"));
I hope it helps!!
I am developing an Android aap that uses Arabic Fonts.
I have successfully display Arabic text by using "tahoma.ttf"
But problem is that these Arabic Fonts Didn't give a cool look.
So i wanted to change that Font Style. Is there any way of doing this ?
If you want to use external font do :
First step is to pick a font that you want to use.
Create a fonts folder in your assets directory and copy your font there.
To access your custom font,use the Typeface class in the Android SDK to create a typeface that Android can use, then set any display elements that need to use your custom font appropriately.
Unfortunately, you can no longer use layout XML for this, since the XML does not know about any fonts you may have tucked away as an application asset.You can do like this in your code:
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/BPreplay.otf");
TextView tv = (TextView) findViewById(R.id.CustomFontText);
tv.setTypeface(tf);
Note: Android does not seem to like all TrueType fonts.So, if you try to use a different font and it does not seem to be working, it may be that the font is incompatible with Android, for whatever reason.
You can see more details in these pages:
Fun with Fonts
Musings of the Bare Bones Coder/using custom fonts