本文整理汇总了Java中android.widget.TextView.getTypeface方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.getTypeface方法的具体用法?Java TextView.getTypeface怎么用?Java TextView.getTypeface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getTypeface方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AuthorView
import android.widget.TextView; //导入方法依赖的package包/类
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();
}
示例2: replaceFont
import android.widget.TextView; //导入方法依赖的package包/类
/**
* <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);
}
}
}
示例3: applyTypeface
import android.widget.TextView; //导入方法依赖的package包/类
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;
}
}
示例4: applyForView
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 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);
}
}
示例5: setCustomFont
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 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);
}
}