Java Code Examples for android.widget.TextView.getTypeface()

The following are Jave code examples for showing how to use getTypeface() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Nird2   File: AuthorView.java   View Source Code Vote up 6 votes
public AuthorView(Context context, @Nullable AttributeSet attrs) {
	super(context, attrs);

	LayoutInflater inflater = (LayoutInflater) context
			.getSystemService(LAYOUT_INFLATER_SERVICE);
	inflater.inflate(R.layout.author_view, this, true);

	avatar = (CircleImageView) findViewById(R.id.avatar);
	avatarIcon = (ImageView) findViewById(R.id.avatarIcon);
	authorName = (TextView) findViewById(R.id.authorName);
	authorNameTypeface = authorName.getTypeface();
	date = (TextView) findViewById(R.id.dateView);
	trustIndicator = (TrustIndicatorView) findViewById(R.id.trustIndicator);

	TypedArray attributes =
			context.obtainStyledAttributes(attrs, R.styleable.AuthorView);
	int persona = attributes.getInteger(R.styleable.AuthorView_persona, 0);
	setPersona(persona);
	attributes.recycle();
}
 
Example 2
Project: Nird2   File: AuthorView.java   View Source Code Vote up 6 votes
public AuthorView(Context context, @Nullable AttributeSet attrs) {
	super(context, attrs);

	LayoutInflater inflater = (LayoutInflater) context
			.getSystemService(LAYOUT_INFLATER_SERVICE);
	inflater.inflate(R.layout.author_view, this, true);

	avatar = (CircleImageView) findViewById(R.id.avatar);
	avatarIcon = (ImageView) findViewById(R.id.avatarIcon);
	authorName = (TextView) findViewById(R.id.authorName);
	authorNameTypeface = authorName.getTypeface();
	date = (TextView) findViewById(R.id.dateView);
	trustIndicator = (TrustIndicatorView) findViewById(R.id.trustIndicator);

	TypedArray attributes =
			context.obtainStyledAttributes(attrs, R.styleable.AuthorView);
	int persona = attributes.getInteger(R.styleable.AuthorView_persona, 0);
	setPersona(persona);
	attributes.recycle();
}
 
Example 3
Project: FamilyBond   File: TypefaceUtil.java   View Source Code Vote up 6 votes
/**
 * <p>Replace the font of specified view and it's children</p>
 * @param root The root view.
 * @param fontPath font file path relative to 'assets' directory.
 */
public static void replaceFont(@NonNull View root, String fontPath) {
    if (root == null || TextUtils.isEmpty(fontPath)) {
        return;
    }


    if (root instanceof TextView) { // If view is TextView or it's subclass, replace it's font
        TextView textView = (TextView)root;
        int style = Typeface.NORMAL;
        if (textView.getTypeface() != null) {
            style = textView.getTypeface().getStyle();
        }
        textView.setTypeface(createTypeface(root.getContext(), fontPath), style);
    } else if (root instanceof ViewGroup) { // If view is ViewGroup, apply this method on it's child views
        ViewGroup viewGroup = (ViewGroup) root;
        for (int i = 0; i < viewGroup.getChildCount(); ++i) {
            replaceFont(viewGroup.getChildAt(i), fontPath);
        }
    }
}
 
Example 4
Project: MobileMedia   File: Icon.java   View Source Code Vote up 6 votes
public static void applyTypeface(TextView v) {
    if (v.getTypeface() == null) {
        v.setTypeface(getNormal(v.getContext()));
        return;
    }
    switch (v.getTypeface().getStyle()) {
        case Typeface.BOLD:
            v.setTypeface(getNormal(v.getContext()));
            v.getPaint().setFakeBoldText(true);
            break;
        default:
            v.setTypeface(getNormal(v.getContext()));
            break;
        case Typeface.ITALIC:
            v.setTypeface(getNormal(v.getContext()));
            v.getPaint().setTextSkewX(-0.25f);
            break;
        case Typeface.BOLD_ITALIC:
            v.setTypeface(getNormal(v.getContext()));
            v.getPaint().setFakeBoldText(true);
            v.getPaint().setTextSkewX(-0.25f);
            break;
    }

}
 
Example 5
Project: GitHub   File: TypefaceHelper.java   View Source Code Vote up 5 votes
/**
 * Apply typeface to single view
 *
 * @param view      to typeface typeface
 * @param typefaceCollection typeface collection
 */
private static void applyForView(View view, TypefaceCollection typefaceCollection) {

	if (view instanceof TextView) {
		TextView textView = (TextView) view;
		Typeface oldTypeface = textView.getTypeface();
		final int style = oldTypeface == null ? Typeface.NORMAL : oldTypeface.getStyle();
		textView.setTypeface(typefaceCollection.getTypeface(style));
		textView.setPaintFlags(textView.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
	}
}
 
Example 6
Project: AACustomFont   File: AACustomFont.java   View Source Code Vote up 5 votes
/**
 * Static method for setting the typeface for the given View
 * The font file should be placed in assets folder in the directory of fonts.
 * Any view that has parent class of TextView can easily use this method.
 *
 * @param view     typeface view
 * @param fontName font name
 */
public static void setCustomFont(View view, String fontName) {
    if (view instanceof TextView) {
        Context context = view.getContext();
        Typeface font = getInstance(context).get(fontName);
        TextView textView = (TextView) view;
        if (textView.getTypeface() != font)
            textView.setTypeface(font);
    }
}