Skip to content

Instantly share code, notes, and snippets.

@lsurvila
Created September 3, 2015 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsurvila/8db93b888997a82dd887 to your computer and use it in GitHub Desktop.
Save lsurvila/8db93b888997a82dd887 to your computer and use it in GitHub Desktop.
Binds font file to TextView using Data Binding API
// from https://plus.google.com/u/0/+LisaWrayZeitouni/posts/LTr5tX5M9mb
@BindingAdapter({"bind:font"})
public static void setFont(TextView textView, String fontName){
textView.setTypeface(Typeface.createFromAsset(textView.getContext().getAssets(), "fonts/" + fontName));
}
<TextView
app:font="@{`Source-Sans-Pro-Regular.ttf`}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment