Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <com.app.customview.DefaultTextView
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:text="@string/especifico_label"
  5. android:textSize="28sp"
  6. android:layout_marginTop="9dp"
  7. android:layout_gravity="center"/>
  8.  
  9. public class DefaultTextView extends android.support.v7.widget.AppCompatTextView {
  10.  
  11. private boolean isLight = false;
  12.  
  13. public DefaultTextView(Context context) {
  14. super(context);
  15. setFont();
  16. }
  17.  
  18. public DefaultTextView(Context context, AttributeSet attrs) {
  19. super(context, attrs);
  20. setAttr(context, attrs);
  21. setFont();
  22. }
  23.  
  24. public DefaultTextView(Context context, AttributeSet attrs, int defStyleAttr) {
  25. super(context, attrs, defStyleAttr);
  26. setAttr(context, attrs);
  27. setFont();
  28. }
  29.  
  30. private void setAttr(Context context, AttributeSet attrs) {
  31. TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Font, 0, 0);
  32. isLight = typedArray.getBoolean(R.styleable.Font_isLight, false);
  33. typedArray.recycle();
  34. }
  35.  
  36. private void setFont() {
  37. if(!isInEditMode()) {
  38. String tf;
  39.  
  40. if(getTypeface()!=null) {
  41. switch (getTypeface().getStyle()) {
  42. case Typeface.ITALIC:
  43. tf = "fonts/segoeuii.ttf";
  44. break;
  45. default:
  46. tf = "fonts/segoeui.ttf";
  47. break;
  48. }
  49.  
  50. } else {
  51. tf = "fonts/segoeui.ttf";
  52. }
  53.  
  54. if(isLight) {
  55. tf = "fonts/segoeuil.ttf";
  56. }
  57.  
  58. setTypeface(Typeface.createFromAsset(getContext().getAssets(), tf));
  59. setTextColor(Color.WHITE);
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement