typeface
TRANSCRIPT
Typeface@KeithYokoma - Drivemode, Inc.
potatotips #9
About myself• KeithYokoma
• Keishin Yokomaku
• Drivemode, Inc.
• GitHub: https://github.com/KeithYokoma
• e-Book: http://amzn.to/1mZNydv
2
Typeface
Typeface
Typeface
Typeface
Typeface
Typeface
Typeface
Typeface
Typeface
Typeface
Typeface
Typeface
Typeface
Typeface
Typeface
TypefaceTypeface Typeface Typeface
Typeface Typeface Typeface
3
4 http://bit.ly/1rjOdtN
Typeface• Cool
• Nice
• Beautiful
• Android provides Roboto by default
5
Typeface• If you would like to change the typeface…
TextView#setTypeface(Typeface)
Paint#setTypeface(Typeface)
Button#setTypeface(Typeface)
EditText#setTypeface(Typeface)
6
Typeface• Read Typeface from your assets
Typeface.createFromAsset(AssetManager, String)
7
Typeface• Read Typeface from your assets
!
• Caution!
Typeface.createFromAsset(AssetManager, String)
Typeface.createFromAsset leaks asset stream!http://bit.ly/1rVOkir
8
Typeface• Workaround: cache
private final Hashtable<String, Typeface> mCache = new Hashtable<String, Typeface>();!private final Application mApplication;!!public synchronized Typeface get(String name) {!! Typeface typeface = mCache.get(name);!! if(typeface == null) {!! ! try {!! ! ! typeface = Typeface.createFromAsset(mApplication.getAssets(), name);!! ! } catch (Exception exp) {!! ! ! return null;!! ! }!! ! mCache.put(name, typeface);!! }!! return typeface;!}
9
Typeface• If you would like to change the typeface for
ActionBar title
Dialog button texts
Dialog message text
ActionBar tab text
All text views in the view group
blah blah blah…
10
Typeface• Got it, we introduce you our library!
TypefaceHelper - http://bit.ly/1AxfqLz
11
Typeface• First, initialize the object in your Application.
public class SampleApp extends Application {!! @Override!! public void onCreate() {!! ! super.onCreate();!! ! TypefaceHelper.initialize(this);!! }!!! @Override!! public void onTerminate() {!! ! TypefaceHelper.destroy();!! ! super.onTerminate();!! }!}
12
Typeface• Set your Typeface.
public class SampleActivity extends Activity {!!! TextView mTextView;!!! @Override!! public void onCreate(Bundle icicle) {!! ! // …!! ! TypefaceHelper helper = TypefaceHelper.getInstance();!! ! helper.setTypeface(this, “MyFont.ttf”);!! ! helper.setTypeface(mTextView, “Another.ttf”);!! }!}
13
Typeface• That's it. Just do it!
14
Typeface• You can set your Typeface to…
• All views that is a child of TextView.
• All TextViews that is belong to ViewGroup.
• Activity, Fragment, Dialog.
• Canvas(thanks to Nohana team!)
15
Typeface• Works in progress
1. OptionsMenu
2. Preferences
3. Set typeface by annotation
16
Typeface@KeithYokoma - Drivemode, Inc.
potatotips #9