-
-
Save tungphan-agilityio/1a202000fb23965cc8d3cf8f66d0dd2c to your computer and use it in GitHub Desktop.
Revisions
-
Johnyoat revised this gist
Jun 13, 2019 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ import android.content.Context import android.graphics.Typeface import timber.log.Timber class TypefaceUtil{ fun overridefonts(context: Context, defaultFontToOverride:String, customFontFileNameInAssets:String){ try { -
Johnyoat created this gist
Jun 13, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ class MyApp : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val typefaceUtil = TypefaceUtil() typefaceUtil.overridefonts(this,"SERIF","fonts/roboto.ttf") } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ class TypefaceUtil{ fun overridefonts(context: Context, defaultFontToOverride:String, customFontFileNameInAssets:String){ try { val customTypeface = Typeface.createFromAsset(context.assets,customFontFileNameInAssets) val defaultTypefaceField = Typeface::class.java.getDeclaredField(defaultFontToOverride) defaultTypefaceField.isAccessible = true defaultTypefaceField.set(null,customTypeface) }catch (e:Exception){ Timber.e("Cannot set font $customFontFileNameInAssets instead of $defaultFontToOverride") } } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ <resources> <!-- 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> </style> </resources>