Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.hjanos.remoteunlock;
- import android.content.Context;
- import android.graphics.Typeface;
- import android.util.AttributeSet;
- import static android.graphics.Typeface.BOLD;
- import static android.graphics.Typeface.ITALIC;
- public class FontEditText extends android.support.v7.widget.AppCompatEditText {
- public FontEditText(Context context) {
- super(context);
- }
- public FontEditText(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public FontEditText(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- }
- @Override
- public void setTypeface(Typeface tf, int style) {
- String fileName = getFileNameForStyle(style);
- Typeface myFont = Typeface.createFromAsset(getContext().getAssets(), fileName);
- super.setTypeface(myFont, style);
- }
- private String getFileNameForStyle(int style) {
- switch (style) {
- case BOLD:
- return "Font_bold.ttf";
- case ITALIC:
- return "Font_italic.ttf";
- case BOLD & ITALIC:
- return "Font_bold_italic.ttf";
- default:
- return "Font_normal.ttf";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement