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
changeFontButton.setOnClickListener { | |
FontsContractCompat.requestFont(applicationContext, createFontRequest(fonts[nextFontIndex]), callback, Handler()) | |
} |
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
val callback = object : FontsContractCompat.FontRequestCallback() { | |
override fun onTypefaceRetrieved(typeface: Typeface?) { | |
textCode.typeface = typeface | |
} | |
override fun onTypefaceRequestFailed(reason: Int) { | |
Log.i("MainActivity", "onTypefaceRequestFailed with code: " + reason) | |
} | |
} |
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
fun createFontRequest(fontName: String) = FontRequest( | |
"com.google.android.gms.fonts", | |
"com.google.android.gms", | |
fontName, | |
R.array.com_google_android_gms_fonts_certs) |
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
val fonts = listOf("Abril Fatface", "Acme", "Aguafina Script", "Aldrich", | |
"Almendra SC", "Architects Daughter", "Arizonia", "Audiowide", "Baloo") |
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
<application | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme"> | |
<!-- rest of content --> | |
</application> |
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
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
<item name="fontFamily">@font/abril_fatface</item> | |
</style> |
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
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
<item name="fontFamily">@font/abril_fatface</item> | |
</style> |
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
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | |
<item name="colorPrimary">@color/colorPrimary</item> | |
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
<item name="colorAccent">@color/colorAccent</item> | |
<item name="fontFamily">@font/abril_fatface</item> | |
</style> |
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
<TextView | |
android:id="@+id/textXML" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:fontFamily="@font/abril_fatface" | |
android:text="This font was set via XML" | |
android:textSize="30sp" /> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_margin="16dp" | |
android:orientation="vertical"> | |
<TextView | |
android:id="@+id/textXML" | |
android:layout_width="match_parent" |
NewerOlder