Skip to content

Instantly share code, notes, and snippets.

Marcin Stramowski stramek

Block or report user

Report or block stramek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View MainActivity.kt
changeFontButton.setOnClickListener {
FontsContractCompat.requestFont(applicationContext, createFontRequest(fonts[nextFontIndex]), callback, Handler())
}
View MainActivity.kt
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)
}
}
View MainActivity.kt
fun createFontRequest(fontName: String) = FontRequest(
"com.google.android.gms.fonts",
"com.google.android.gms",
fontName,
R.array.com_google_android_gms_fonts_certs)
View MainActivity.kt
val fonts = listOf("Abril Fatface", "Acme", "Aguafina Script", "Aldrich",
"Almendra SC", "Architects Daughter", "Arizonia", "Audiowide", "Baloo")
View AndroidManifest.xml
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<!-- rest of content -->
</application>
View styles.xml
<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>
View styles.xml
<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>
View styles.xml
<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>
View activity_main.xml
<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" />
View activity_main.xml
<?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"
You can’t perform that action at this time.