Design

Using Custom and Downloadable Fonts in Android

To work with Custom Font, you need to install the latest version of Android Studio. A font resource defines a custom font that you can use in your app. Fonts can be individual font files or a collection of font files

2022-04-14
Share this

Today I will show you how to use Custom and Downloadable Fonts in Android for your project. Here is use caveat regular font which I downloaded from the web/internet. You can get the full source code below to press the download code button or if you are facing any difficulty understanding you can take a look at my video where I explain every step of this project. Anyways I use androidX. There are two ways to change fonts and use custom fonts in your project. First, you need to create a folder name of assets and add the TTF file to it. and the following code to the MainActivity.java page.

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView text_change;
  //  Typeface cregular;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text_change=findViewById(R.id.text_change);
       cregular=Typeface.createFromAsset(getAssets(),"caveatregular.ttf");
        text_change.setTypeface(cregular);


    }
}

And you can check and run the project. You will see your custom font in your application. Now the second way is you need to create a folder in res named font and add the TTF file into it. Now create a folder named regular and add the following code to it.

<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <font
        android:fontStyle="normal"
        android:fontWeight="400"
        android:font="@font/caveatregular"
        app:fontStyle="normal"
        app:fontWeight="400"
        app:font="@font/caveatregular"
        />
</font-family>

Today I will show you how to use Custom and Downloadable Fonts in Android for your project. Here is use caveat regular font which I downloaded from the web/internet. You can get the full source code below to press the download code button or if you are facing any difficulty understanding you can take a look at my video where I explain every step of this project. Anyways I use androidX. There are two ways to change fonts and use custom fonts in your project. First, you need to create a folder name of assets and add the TTF file to it. and the following code to the MainActivity.java page.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/text_change"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/content"
        android:textSize="20sp"
        android:fontFamily="@font/cregular"
        android:gravity="center"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Today I will show you how to use Custom and Downloadable Fonts in Android for your project. Here is use caveat regular font which I downloaded from the web/internet. You can get the full source code below to press the download code button or if you are facing any difficulty understanding you can take a look at my video where I explain every step of this project. Anyways I use androidX. There are two ways to change fonts and use custom fonts in your project. First, you need to create a folder name of assets and add the TTF file to it. and the following code to the MainActivity.java page.

Read next

Android studio Hello world project for Beginner step by step

The first step is to create a simple Android Application using Android studio. Its very simple. Follow My code step by step or youtube video.

Sun, 27 Mar 2022

Modal Bottom Sheet in Androidx with Examples - Working with BottomSheet

A user can view the full Bottom Sheet by dragging the sheet up vertically. Bottom Sheets are a lesser known part of the Design support library.
Thu, 21 Apr 2022

Android Custom RecyclerView with Text using AndroidX

RecyclerView was introduced in Material Design in API level 21 (Android 5.0 i.e Lollipop). Material Design brings lot of new features in Android that changed a lot the visual design patterns regarding the designing of modern Android applications. Here you can see my YouTube video. You can get visual view from that. I resound again and again that if you have any query comment me in myandroidmaster.com comment section or on YouTube Comment Section.
Mon, 11 Apr 2022