I am new in android app development. I want to change fonts of my Application. Just i wanna know different methods for change the font by XML and Java to. Want to change the font of : 1.TextView 2.RadioButton 3.EditText 4.CheckBox etc.
6 Answers
- In Android Studio Right click on app & create a folder assets.
Right click on assets and create a folder fonts.
Download .ttf file i.e fontName.ttf and paste inside fonts folder.
Now you have to do main things. Inside your package create a class.
This class is for TextView
public class Railway_Regular extends TextView {
public Railway_Regular(Context context, AttributeSet attrs) {
super(context, attrs);
this.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/Raleway-Regular.ttf"));
}}
This class is for Button
public class Railway_Regular_Btn extends Button {
public Railway_Regular_Btn(Context context, AttributeSet attrs) {
super(context, attrs);
this.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/Raleway-Regular.ttf"));
}}
This class is for EditText
public class Railway_Regular_EdTx extends EditText {
public Railway_Regular_EdTx(Context context, AttributeSet attrs) {
super(context, attrs);
this.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/Raleway-Regular.ttf"));
}}
Like these you can create classes for all you Widgets & reference the fontname.ttf to your classes.
Now,for set textview as your font do this.
for TextView
<package_name.fonts.Railway_Regular
android:padding="5sp"
android:id="@+id/test_nameDR"
android:layout_marginTop="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Details Text"
android:textColor="@color/black"
android:textSize="14sp"/>
for Button
<package_name.fonts.Railway_Regular_Btn
android:id="@+id/revSubmit"
android:background="@color/greenDeep"
android:layout_marginTop="-54dp"
android:layout_width="match_parent"
android:layout_height="54dp"
android:textColor="@color/white"
android:textSize="16dp"
android:text="SUBMIT REVIEW"
/>
for EditText
<package_name.fonts.Railway_Regular_EdTx
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="15dp"
android:textColorHint="@color/lightgray"
android:textSize="14dp"
android:background="@drawable/edit_text"
android:id="@+id/email_id"
android:hint="Email Id"
android:inputType="textEmailAddress" />
Second Method to Change your font :
Typeface typeface,typeface2;
typeface = Typeface.createFromAsset(this.getAssets(),"fonts/Raleway-Regular.ttf");
typeface2 = Typeface.createFromAsset(this.getAssets(),"fonts/Raleway-SemiBold.ttf");
button1.setTypeface(typeface);
edit_text1.setTypeface(typeface2);

- 1,255
- 13
- 21
You can use TTF format to change the font
tv1=(TextView)findViewById(R.id.textView3);
tv2=(TextView)findViewById(R.id.textView4);
Typeface face= Typeface.createFromAsset(getAssets(), "font/font.ttf");
tv1.setTypeface(face);
Typeface face1= Typeface.createFromAsset(getAssets(), "font/font1.ttf");
tv2.setTypeface(face1);
https://www.tutorialspoint.com/android/android_custom_fonts.htm
http://tekeye.uk/android/examples/android-textview-edittext-font

- 13,409
- 16
- 61
- 96
You can do it programmatically using the below code for RadioButton/TextView/Checkbox -
Also make sure that you have the corresponding .ttf file inside your Assets folder.
RadioButton rb = (RadioButton) findViewById(R.id.radiobutton);
Typeface font = Typeface.createFromAsset(getAssets(), "SF_Cartoonist_Hand_Bold.ttf");
rb.setTypeface(font);
Or you can do it inside your xml file inside your TextView by entering this -
From android 4.1 / 4.2 / 5.0, the following Roboto font families are available:
android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed
android:fontFamily="sans-serif-black" // roboto black
android:fontFamily="sans-serif-thin" // roboto thin (android 4.2)
android:fontFamily="sans-serif-medium" // roboto medium (android 5.0)

- 1,991
- 19
- 25
You can change font of your application so create fonts folder under assets folder in your project and put your TTF into it.May be It will help you How to add external fonts to android application

- 508
- 4
- 13
You can use various methods to change your font. One of them is:
Typeface typeface,typeface2;
typeface = Typeface.createFromAsset(this.getAssets(),"fonts/Raleway-
Regular.ttf");
typeface2 = Typeface.createFromAsset(this.getAssets(),"fonts/Raleway-
SemiBold.ttf");
button1.setTypeface(typeface);
edit_text1.setTypeface(typeface2);

- 1,245
- 1
- 14
- 29
In themes.xml
, I put this line into the theme, which was assigned to the app in AndroidManifest.xml
:
<item name="android:fontFamily">EnterFontFamilyNameHere</item>

- 1,019
- 3
- 16