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.