Skip to content

Instantly share code, notes, and snippets.

@timkrins
Created April 23, 2017 12:14
Show Gist options
  • Save timkrins/845310be17aa0b804f0db5e8bd035484 to your computer and use it in GitHub Desktop.
Save timkrins/845310be17aa0b804f0db5e8bd035484 to your computer and use it in GitHub Desktop.
TextInputLayout for using the default Calligraphy font
package com.timkrins.templates.ui.custom;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
import uk.co.chrisjenx.calligraphy.TypefaceUtils;
/**
* TextInputLayout for use with the default Calligraphy font
*/
public class CalligraphyDefaultTextInputLayout extends android.support.design.widget.TextInputLayout {
Typeface calligraphyTypeface;
public CalligraphyDefaultTextInputLayout(Context context) {
super(context);
initCalligraphyTypeface();
}
public CalligraphyDefaultTextInputLayout(Context context, AttributeSet attrs) {
super(context, attrs);
initCalligraphyTypeface();
}
public CalligraphyDefaultTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initCalligraphyTypeface();
}
@Override
public void addView(View child, int index, final ViewGroup.LayoutParams params) {
super.addView(child, index, params);
if (child instanceof EditText) {
if (calligraphyTypeface != null) {
setTypeface(calligraphyTypeface);
}
}
}
private void initCalligraphyTypeface() {
String fontPath = CalligraphyConfig.get().getFontPath();
if(fontPath != null) {
calligraphyTypeface = TypefaceUtils.load(getResources().getAssets(), fontPath);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment