/** * Setup Roboto typeface. * * @param context The Context the widget is running in, through which it can access the current * theme, resources, etc. * @param attrs The attributes of the XML tag that is inflating the widget. * @param defStyle The default style to apply to this widget. If 0, no style will be applied * (beyond what is included in the theme). */ private void onInitTypeface(Context context, AttributeSet attrs, int defStyle) { // Typeface.createFromAsset doesn't work in the layout editor, so skipping. if (isInEditMode()) { return; } int typefaceValue = 0; if (attrs != null) { TypedArray values = context.obtainStyledAttributes(attrs, R.styleable.RobotoTextView, defStyle, 0); typefaceValue = values.getInt(R.styleable.RobotoTextView_typeface, 0); values.recycle(); } Typeface robotoTypeface = RobotoTypefaceManager.obtaintTypeface(context, typefaceValue); setTypeface(robotoTypeface); }