Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package com.hjanos.remoteunlock;
  2.  
  3. import android.content.Context;
  4. import android.graphics.Typeface;
  5. import android.util.AttributeSet;
  6.  
  7. import static android.graphics.Typeface.BOLD;
  8. import static android.graphics.Typeface.ITALIC;
  9.  
  10. public class FontEditText extends android.support.v7.widget.AppCompatEditText {
  11.  
  12. public FontEditText(Context context) {
  13. super(context);
  14. }
  15.  
  16. public FontEditText(Context context, AttributeSet attrs) {
  17. super(context, attrs);
  18. }
  19.  
  20. public FontEditText(Context context, AttributeSet attrs, int defStyleAttr) {
  21. super(context, attrs, defStyleAttr);
  22. }
  23.  
  24. @Override
  25. public void setTypeface(Typeface tf, int style) {
  26. String fileName = getFileNameForStyle(style);
  27.  
  28. Typeface myFont = Typeface.createFromAsset(getContext().getAssets(), fileName);
  29. super.setTypeface(myFont, style);
  30. }
  31.  
  32. private String getFileNameForStyle(int style) {
  33. switch (style) {
  34. case BOLD:
  35. return "Font_bold.ttf";
  36. case ITALIC:
  37. return "Font_italic.ttf";
  38. case BOLD & ITALIC:
  39. return "Font_bold_italic.ttf";
  40. default:
  41. return "Font_normal.ttf";
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement