Skip to content

Instantly share code, notes, and snippets.

@Johnyoat Johnyoat/MyApp.kt
Last active Sep 25, 2019

What would you like to do?
Changing or setting one font for all text font in android in Kotlin
class MyApp : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
val typefaceUtil = TypefaceUtil()
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- you should set typeface which you want to override with TypefaceUtil -->
<item name="android:typeface">serif</item>
import android.content.Context
import timber.log.Timber
class TypefaceUtil{
fun overridefonts(context: Context, defaultFontToOverride:String, customFontFileNameInAssets:String){
try {
val customTypeface = Typeface.createFromAsset(context.assets,customFontFileNameInAssets)
val defaultTypefaceField =
defaultTypefaceField.isAccessible = true
}catch (e:Exception){
Timber.e("Cannot set font $customFontFileNameInAssets instead of $defaultFontToOverride")

This comment has been minimized.

Copy link

commented Sep 25, 2019

Is there away I can set default different fonts for bold and normal texts such that all normal texts have their own fonts while bold texts have different font?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.