Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom Font in Android Studio
package com.codingwithsara.customfont;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView myText;
Typeface customFont;
Boolean change = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myText = findViewById(R.id.myText);
customFont = Typeface.createFromAsset(getAssets(), "Lobster-Regular.ttf");
}
public void switchFont(View view) {
if (change) {
myText.setText("Custon Font");
myText.setTypeface(customFont);
} else {
myText.setText("Default");
myText.setTypeface(Typeface.DEFAULT);
}
change = !change;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment