本文整理汇总了Java中android.text.TextPaint.getTypeface方法的典型用法代码示例。如果您正苦于以下问题:Java TextPaint.getTypeface方法的具体用法?Java TextPaint.getTypeface怎么用?Java TextPaint.getTypeface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.TextPaint
的用法示例。
在下文中一共展示了TextPaint.getTypeface方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTextWidth
import android.text.TextPaint; //导入方法依赖的package包/类
private static int getTextWidth(@Nullable final CharSequence text, final TextPaint paint) {
if (TextUtils.isEmpty(text)) {
return 0;
}
final int length = text.length();
final float[] widths = new float[length];
final int count;
final Typeface savedTypeface = paint.getTypeface();
try {
paint.setTypeface(getTextTypeface(text));
count = paint.getTextWidths(text, 0, length, widths);
} finally {
paint.setTypeface(savedTypeface);
}
int width = 0;
for (int i = 0; i < count; i++) {
width += Math.round(widths[i] + 0.5f);
}
return width;
}
示例2: apply
import android.text.TextPaint; //导入方法依赖的package包/类
private void apply(TextPaint paint) {
int oldStyle;
Typeface old = paint.getTypeface();
if (old == null) {
oldStyle = 0;
} else {
oldStyle = old.getStyle();
}
final int fakeStyle = oldStyle & ~typeface.getStyle();
if ((fakeStyle & Typeface.BOLD) != 0) {
paint.setFakeBoldText(true);
}
if ((fakeStyle & Typeface.ITALIC) != 0) {
paint.setTextSkewX(-0.25f);
}
paint.setTypeface(typeface);
}
示例3: updateTypeface
import android.text.TextPaint; //导入方法依赖的package包/类
private void updateTypeface(TextPaint ds) {
Typeface typeface = ds.getTypeface();
int oldStyle = (typeface == null) ? 0 : typeface.getStyle();
int newStyle = getNewStyle(oldStyle);
if (oldStyle == newStyle && mFontFamily == null) {
// nothing to do
return;
}
if (mFontFamily != null) {
typeface = TypefaceCache.getTypeface(mFontFamily, newStyle);
} else {
typeface = TypefaceCache.getTypeface(typeface, newStyle);
}
ds.setTypeface(typeface);
}
示例4: CandidateView
import android.text.TextPaint; //导入方法依赖的package包/类
/**
* Construct a CandidateView for showing suggested words for completion.
* @param context context
*/
public CandidateView(Context context) {
super(context);
mService = (QuranKeyboardIME) context;
mSelectionHighlight = ContextCompat.getDrawable(context,
android.R.drawable.list_selector_background);
mSelectionHighlight.setState(new int[] {
android.R.attr.state_enabled,
android.R.attr.state_focused,
android.R.attr.state_window_focused,
android.R.attr.state_pressed
});
Resources r = context.getResources();
setBackgroundColor(ContextCompat.getColor(context, R.color.candidate_background));
mColorNormal = ContextCompat.getColor(context, R.color.candidate_normal);
mColorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended);
mColorOther = ContextCompat.getColor(context, R.color.candidate_other);
mVerticalPadding = r.getDimensionPixelSize(R.dimen.candidate_vertical_padding);
mPaint = new TextPaint();
mPaint.setColor(mColorNormal);
mPaint.setAntiAlias(true);
mPaint.setTextSize(r.getDimensionPixelSize(R.dimen.candidate_font_height));
mPaint.setStrokeWidth(0);
mDefaultTf = mPaint.getTypeface();
mUthamniTf = mService.getUthmaniTypeFace();
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
mScrolled = true;
int sx = getScrollX();
sx += distanceX;
if (sx < 0) {
sx = 0;
}
if (sx + getWidth() > mTotalWidth) {
sx -= distanceX;
}
mTargetScrollX = sx;
scrollTo(sx, getScrollY());
invalidate();
return true;
}
});
setHorizontalFadingEdgeEnabled(true);
setWillNotDraw(false);
setHorizontalScrollBarEnabled(false);
setVerticalScrollBarEnabled(false);
}