-
-
Save codingwithsara/a4e8debd7bb3ecf084ecc1c33eb30787 to your computer and use it in GitHub Desktop.
Custom Font in Android Studio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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