Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created November 18, 2018 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/a4e8debd7bb3ecf084ecc1c33eb30787 to your computer and use it in GitHub Desktop.
Save codingwithsara/a4e8debd7bb3ecf084ecc1c33eb30787 to your computer and use it in GitHub Desktop.
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