I want to show text in Arial font. But Arial font is not available in android system fonts. I don't want to use arial ttf file in my application. Is there any other way to apply text with Arial font.
-
4Nope. Any font that is not available inherently will need the `.ttf` / `.otf`. – Siddharth Lele Apr 24 '13 at 05:02
-
Can I use ttf file directly into my application. Is there any licensing issue? – jkstar Apr 24 '13 at 05:24
-
5Not all fonts are free to use for commercial purposes. So be sure to check before using it. That being said, I always typically head down to http://www.fontsquirrel.com/ which has a huge collection of freeware fonts. Better safe than sorry. ;-) As for licensing for the Arial font, check this link on Wikipedia: http://en.wikipedia.org/wiki/Arial#Free_alternatives – Siddharth Lele Apr 24 '13 at 05:27
-
Nope, you have to use ttf for arial font . – Abhijit Chakra Apr 24 '13 at 05:27
-
how to use custom font. Can you please provide some example. – jkstar Apr 24 '13 at 06:06
-
http://vimaltuts.com/android-tutorial-for-beginners/android-custom-font-example – QuokMoon Apr 24 '13 at 06:09
-
Without putting any file to your application, how is it possible to use any font which is not in device. Suppose some phone has that fonts, but some not. How you deal with this scenario? – Chintan Rathod Apr 24 '13 at 06:14
-
@Keerthi: Take a look at an answer of mine here: http://stackoverflow.com/a/13539794/450534. It has two alternatives. One is the conventional way of using a custom font in a single `Activity`. The other is how to extend `TextView` and use a specific custom font throughout your application. (The complete solution for this is in a link in the answer). – Siddharth Lele Apr 24 '13 at 06:18
-
Next time try to search http://stackoverflow.com/a/3424559/1616443 – jimpanzer Apr 24 '13 at 06:19
6 Answers
If the font is not available in the android system, then you have to use the font file to apply that particular font say arial to your textView
. May I know why you are not willing to use the font file to apply as it gives the same functionality.
Sample usage for using the font file is:
Typeface tfArial = Typeface.createFromAsset(getAssets(), "arial.ttf");
TextView tv = null;
// find the textview id from layout or create dynamically
tv.setTypeface(tfArial);
EDIT:
You need to put the font file arial.ttf
in your asset
folder.

- 27,623
- 15
- 98
- 151

- 1,044
- 1
- 11
- 17
Download Arial font and in assets create folder name with "fonts" and save font at there
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/arial.ttf");
TextView tv = (TextView) findViewById(R.id.CustomFontText);
tv.setTypeface(tf);

- 2,320
- 3
- 17
- 21
You can create your custom font just adding the .ttf file in "fonts" folder inside "res":
The xml files contain this:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:font="@font/nunito_extrabold"
android:fontStyle="normal"
android:fontWeight="400" />
</font-family>
And that's all! You can use this font in every TextView just adding android:fontFamily property.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/font_semibold"
android:text="@string/custom_font" />

- 8,467
- 5
- 38
- 42
You can add google font family from android studio by going to
- xml design
- add font family then there is limitem font family so click on
- more font family ( this is google font you can choose either add font or downloadable font)
- add font then click ok then the font will be added in your font list and you can use like default font.

- 47
- 3
Consider using Calligraphy to have any custom font in your Android application.
You will not need to add code in each TextView to apply a font. Simply initialise at application startup and you're good to go.

- 61
- 6
Create a TextView from Java Code or XML like this
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:textSize="15sp"
android:textColor="@color/tabs_default_color"
android:gravity="center"
android:layout_height="match_parent"
/>
Make sure to keep the id as it is here because the TabLayout check for this ID if you use custom textview
Then from code inflate this layout and set the custom Typeface
on that textview and add this custom view to the tab
for (int i = 0; i < tabLayout.getTabCount(); i++) {
//noinspection ConstantConditions
TextView tv=(TextView)LayoutInflater.from(this).inflate(R.layout.custom_tab,null)
tv.setTypeface(Typeface);
tabLayout.getTabAt(i).setCustomView(tv);
}

- 89
- 9