android-typeface-helper alternatives and similar packages
Based on the "Font" category.
Alternatively, view android-typeface-helper alternatives based on common mentions on social networks and blogs.
-
Calligraphy
Custom fonts in Android the easy way... -
fontbinding
A full example of custom fonts in XML using data binding and including font caching. -
Android-Icon-Fonts
Material and Holo iconic fonts. -
Print
A lightweight Android library for use iconic fonts. -
TypefaceHelper
Helper object for injecting typeface into various text views of android. -
Tehreer-Android
Standalone text engine for Android aimed to be free from platform limitations -
Single Shot Font Change
Custom font library for android | Library to change/add font of Entire Android Application at once without wasting your time - TextViews, EditText, Buttons, Views etc.,
Appwrite - The Open Source Firebase alternative introduces iOS support
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of android-typeface-helper or a related project?
README
Android Typeface Helper
Android lacks proper support for custom typefaces. Most obvious method of defining typeface for UI elements via XML attributes is missing from default framework views. This library makes it a lot easier to set custom typefaces from java code - one time initialization inside Application subclas and then applying custom typeface to all View
's via typeface()
static method call.
Sample app (sources available in sample
folder):
Features
- Apply custom typefaces to whole view hierarchy via single call.
- Super easy initialization in Application subclass via
TypefaceHelper.init()
TypefaceHelper.typeface()
applies custom typeface to allTextView
's insideActivity
orViewGroup
TypefaceHelper
can also apply custom typeface toView
, or createSpannableString
with custom font fromStrning
/CharSequence
- Support for multiple typefaces:
TypefaceHelper
can use defaultTypefaceCollection
passed viainit()
or can be parametrized with otherTypefaceCollection
- Support for textStyles:
Typeface.NORMAL
,Typeface.BOLD
,Typeface.ITALIC
andTypeface.BOLD_ITALIC
- Support for dynamic typeface changes
- Support for custom typefaces in ActionBar title
Installation
Via gradle:
compile 'com.norbsoft.typefacehelper:library:0.9.0'
Alternative download AAR here
Usage
- Put your custom true type fonts (TTF) in
assets/fonts
folder - Pass
TypefaceCollection
toTypefaceHelper.init()
in yourApplication
subclass:java @Override public void onCreate() { super.onCreate(); // Initialize typeface helper TypefaceCollection typeface = new TypefaceCollection.Builder() .set(Typeface.NORMAL, Typeface.createFromAsset(getAssets(), "fonts/ubuntu/Ubuntu-R.ttf")) .create(); TypefaceHelper.init(typeface); }
- Apply custom typefaces to
Activity
,ViewGroup
orView
:java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_layout); // Apply custom typefaces! TypefaceHelper.typeface(this); }
## Advanced usage ### Static import fortypeface()
method You can use static import fortypeface()
method:java import static com.norbsoft.typefacehelper.TypefaceHelper.typeface;
and then use it without referencingTypefaceHelper
class: ```java View v = inflater.inflate(R.layout.myview); typeface(v);
### Change font in `ActionBar` title
Pass `ActionBar` instance along with `SpannableString` with custom typeface to `ActionBarHelper.setTitle()` helper:
```java
ActionBarHelper.setTitle(
getSupportActionBar(),
typeface(this, R.string.lorem_ipsum_title));
Apply in AdapterView (ListView, Spinner)
Each time ConvertView
is created inside adapter, it needs to be styled via typeface()
call
listView.setAdapter(new BaseAdapter() {
String[] items = { "Item 1", "Item 2", "Item 3" };
@Override public int getCount() {
return items.length;
}
@Override public Object getItem(int position) {
return items[position];
}
@Override public long getItemId(int position) {
return items[position].hashCode();
}
@Override public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context)
.inflate(android.R.layout.simple_list_item_1, parent, false);
// Apply custom typeface!
typeface(convertView);
}
((TextView) convertView).setText(items[position]);
return convertView;
}
});
Use multiple typefaces and styles
First, define and initialize TypefaceCollection
for each typeface you intend to use in your Application
subclass:
public class MyApplication extends Application {
private TypefaceCollection mArchRivalTypeface;
private TypefaceCollection mUbuntuTypeface;
@Override public void onCreate() {
super.onCreate();
// Initialize Arch Rival typeface
mArchRivalTypeface = new TypefaceCollection.Builder()
.set(Typeface.NORMAL, Typeface.createFromAsset(getAssets(),
"fonts/arch_rival/SF_Arch_Rival.ttf"))
.set(Typeface.BOLD, Typeface.createFromAsset(getAssets(),
"fonts/arch_rival/SF_Arch_Rival_Bold.ttf"))
.set(Typeface.ITALIC, Typeface.createFromAsset(getAssets(),
"fonts/arch_rival/SF_Arch_Rival_Italic.ttf"))
.set(Typeface.BOLD_ITALIC, Typeface.createFromAsset(getAssets(),
"fonts/arch_rival/SF_Arch_Rival_Bold_Italic.ttf"))
.create();
// Initialize Ubuntu typeface
mUbuntuTypeface = new TypefaceCollection.Builder()
.set(Typeface.NORMAL, Typeface.createFromAsset(getAssets(),
"fonts/ubuntu/Ubuntu-R.ttf"))
.set(Typeface.BOLD, Typeface.createFromAsset(getAssets(),
"fonts/ubuntu/Ubuntu-B.ttf"))
.set(Typeface.ITALIC, Typeface.createFromAsset(getAssets(),
"fonts/ubuntu/Ubuntu-RI.ttf"))
.set(Typeface.BOLD_ITALIC, Typeface.createFromAsset(getAssets(),
"fonts/ubuntu/Ubuntu-BI.ttf"))
.create();
// Load helper with default custom typeface (single custom typeface)
TypefaceHelper.init(mUbuntuTypeface);
}
/** Getter for Arch Rival typeface */
public TypefaceCollection getArchRivalTypeface() {
return mArchRivalTypeface;
}
/** Getter for Ubuntu typeface */
public TypefaceCollection getUbuntuTypeface() {
return mUbuntuTypeface;
}
}
Then, call typeface()
and pass custmo TypefaceCollection
:
typeface(findViewById(R.id.label_title),
((MyApplication) getApplication()).getArchRivalTypeface());
typeface(findViewById(R.id.label_subtitle),
((MyApplication) getApplication()).getUbuntuTypeface());
Change typefaces dynamically
Typeface changes each time typeface()
is called - it can be used from onClick()
method:
@Override public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_font_ubuntu:
typeface(findViewById(R.id.label_title),
((MyApplication) getApplication()).getUbuntuTypeface());
break;
case R.id.btn_font_arch_rival:
typeface(findViewById(R.id.label_title),
((MyApplication) getApplication()).getArchRivalTypeface());
break;
}
}
License
Android Typeface Helper is licensed under [http://www.apache.org/licenses/LICENSE-2.0](Apache License 2.0.)
*Note that all licence references and agreements mentioned in the android-typeface-helper README section above
are relevant to that project's source code only.