Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. public class TextViewFont extends TextView {
  2.  
  3. public TextViewFont(Context context, AttributeSet attrs, int defStyle) {
  4. super(context, attrs, defStyle);
  5. init(attrs);
  6. }
  7.  
  8. public TextViewFont(Context context, AttributeSet attrs) {
  9. super(context, attrs);
  10. init(attrs);
  11.  
  12. }
  13.  
  14. public TextViewFont(Context context) {
  15. super(context);
  16. init(null);
  17. }
  18.  
  19. private void init(AttributeSet attrs) {
  20. if (attrs != null) {
  21. TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TextViewFont);
  22. String fontName = a.getString(R.styleable.TextViewFont_fontName);
  23. if (fontName != null) {
  24. Typeface myTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/" + fontName);
  25. setTypeface(myTypeface);
  26. }
  27. a.recycle();
  28. }
  29. }
  30. }
  31.  
  32. <com.eugene.fithealthmaingit.Custom.TextViewFont
  33. android:layout_width="0dp"
  34. android:layout_height="wrap_content"
  35. android:layout_marginLeft="16dp"
  36. android:layout_weight="1"
  37. android:text="@string/dinner"
  38. android:textColor="@color/text_color"
  39. android:textSize="16sp"
  40. app:fontName="Roboto-Regular.ttf"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement