Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TextViewFont extends TextView {
- public TextViewFont(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- init(attrs);
- }
- public TextViewFont(Context context, AttributeSet attrs) {
- super(context, attrs);
- init(attrs);
- }
- public TextViewFont(Context context) {
- super(context);
- init(null);
- }
- private void init(AttributeSet attrs) {
- if (attrs != null) {
- TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TextViewFont);
- String fontName = a.getString(R.styleable.TextViewFont_fontName);
- if (fontName != null) {
- Typeface myTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/" + fontName);
- setTypeface(myTypeface);
- }
- a.recycle();
- }
- }
- }
- <com.eugene.fithealthmaingit.Custom.TextViewFont
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_weight="1"
- android:text="@string/dinner"
- android:textColor="@color/text_color"
- android:textSize="16sp"
- app:fontName="Roboto-Regular.ttf"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement