Last active
September 22, 2015 01:17
-
-
Save monmonja/117b428fd48c52324fd7 to your computer and use it in GitHub Desktop.
Extending Components and AppTheme with Material Design
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 characters
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
xmlns:font="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
tools:context=".MainActivity"> | |
<com.monmonja.tutorial.RadioButtonCustomFont | |
font:name="Regular" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Yes" | |
/> | |
</RelativeLayout> |
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 characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<declare-styleable name="font"> | |
<attr name="name"> | |
<enum name="Regular" value="0"/> | |
<enum name="Thin" value="1"/> | |
<enum name="Medium" value="2"/> | |
<enum name="Light" value="3"/> | |
<enum name="Italic" value="4"/> | |
</attr> | |
</declare-styleable> | |
</resources> |
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 characters
package com.monmonja.tutorial; | |
import android.content.Context; | |
import android.content.res.Resources; | |
import android.graphics.Typeface; | |
import android.widget.TextView; | |
/** | |
* tutorial at http://www.tutorialforandroid.com/2015/03/extending-components-and-apptheme-with.html | |
*/ | |
public class FontUtils { | |
public static int FONT_REGULAR = 0; | |
public static int FONT_THIN = 1; | |
public static int FONT_MEDIUM = 2; | |
public static int FONT_LIGHT = 3; | |
public static int FONT_ITALIC = 4; | |
public static void setTypeface (int fontName, TextView textView) { | |
Typeface font = null; | |
Context context = textView.getContext(); | |
Resources resources = context.getResources(); | |
if (fontName == FontUtils.FONT_REGULAR) { | |
font = Typeface.createFromAsset(context.getAssets(), resources.getString(R.string.font_regular)); | |
} else if (fontName == FontUtils.FONT_THIN) { | |
font = Typeface.createFromAsset(context.getAssets(), resources.getString(R.string.font_thin)); | |
} else if (fontName == FontUtils.FONT_MEDIUM) { | |
font = Typeface.createFromAsset(context.getAssets(), resources.getString(R.string.font_medium)); | |
} else if (fontName == FontUtils.FONT_LIGHT) { | |
font = Typeface.createFromAsset(context.getAssets(), resources.getString(R.string.font_light)); | |
} else if (fontName == FontUtils.FONT_ITALIC) { | |
font = Typeface.createFromAsset(context.getAssets(), resources.getString(R.string.font_italic)); | |
} | |
textView.setTypeface(font); | |
} | |
} |
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 characters
<resources> | |
<style name="FrameworkRoot.Theme" parent="Theme.AppCompat.Light.NoActionBar" /> | |
<!-- Base application theme. --> | |
<style name="AppTheme" parent="FrameworkRoot.Theme"> | |
..... | |
<item name="colorControlNormal">@color/component_normal</item> | |
<item name="colorControlActivated">@color/component_activated</item> | |
<item name="colorControlHighlight">@color/component_highlight</item> | |
<item name="colorAccent">@color/primary_accent_1</item> | |
..... | |
</style> | |
</resources> |
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 characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="font_regular">fonts/NotoSansCJKtc-Bold.oft</string> | |
<string name="font_thin">fonts/NotoSansCJKtc-Bold.oft</string> | |
<string name="font_medium">fonts/NotoSansCJKtc-Bold.oft</string> | |
<string name="font_light">fonts/NotoSansCJKtc-Bold.oft</string> | |
<string name="font_italic">fonts/NotoSansCJKtc-Bold.oft</string> | |
</resources> |
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 characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="font_regular">fonts/Roboto-Regular.ttf</string> | |
<string name="font_thin">fonts/Roboto-Thin.ttf</string> | |
<string name="font_medium">fonts/Roboto-Medium.ttf</string> | |
<string name="font_light">fonts/Roboto-Light.ttf</string> | |
<string name="font_italic">fonts/Roboto-Italic.ttf</string> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment