本文整理匯總了Java中android.text.TextPaint.setTypeface方法的典型用法代碼示例。如果您正苦於以下問題:Java TextPaint.setTypeface方法的具體用法?Java TextPaint.setTypeface怎麽用?Java TextPaint.setTypeface使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.text.TextPaint
的用法示例。
在下文中一共展示了TextPaint.setTypeface方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initPaint
import android.text.TextPaint; //導入方法依賴的package包/類
private void initPaint() {
mTextPaint = new TextPaint();
mTextPaint.setAntiAlias(true);
mTextPaint.setTextSize(getTextSize());
mTextPaint.setColor(mColor);
mTextPaint.setStyle(Paint.Style.FILL);
mTextPaint.setTypeface(getTypeface());
mTextPaintOutline = new TextPaint();
mTextPaintOutline.setAntiAlias(true);
mTextPaintOutline.setTextSize(getTextSize());
mTextPaintOutline.setColor(mBorderColor);
mTextPaintOutline.setStyle(Paint.Style.STROKE);
mTextPaintOutline.setTypeface(getTypeface());
mTextPaintOutline.setStrokeWidth(mBorderSize);
}
示例2: initPaintObjects
import android.text.TextPaint; //導入方法依賴的package包/類
private void initPaintObjects() {
int labelTextSize = getResources().getDimensionPixelSize(R.dimen.label_text_size);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextSize(labelTextSize);
if (typeface != null) {
textPaint.setTypeface(typeface);
}
textPaint.setColor(baseColor);
baseAlpha = textPaint.getAlpha();
selectorPath = new Path();
selectorPath.setFillType(Path.FillType.EVEN_ODD);
selectorPoints = new Point[3];
for (int i = 0; i < 3; i++) {
selectorPoints[i] = new Point();
}
}
示例3: updateDrawState
import android.text.TextPaint; //導入方法依賴的package包/類
@Override
public void updateDrawState(TextPaint tp) {
if (mTypeface != null) {
tp.setTypeface(mTypeface);
}
if (textSize != 0) {
tp.setTextSize(textSize);
}
if (color != 0) {
tp.setColor(color);
}
tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
示例4: LabelLayout
import android.text.TextPaint; //導入方法依賴的package包/類
public LabelLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setWillNotDraw(false);
setAddStatesFromChildren(true);
mInputFrame = new FrameLayout(context);
mInputFrame.setAddStatesFromChildren(true);
super.addView(mInputFrame, -1, generateDefaultLayoutParams());
mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
mTextPaint.setTypeface(Typeface.DEFAULT);// getTypeface());
mTextSizeCollapsed = getResources().getDimensionPixelSize(R.dimen.abc_text_size_caption_material);
mTextSizeExpanded = getResources().getDimensionPixelSize(R.dimen.abc_text_size_medium_material);
mTextPaint.setTextSize(mTextSizeCollapsed);
StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(context, attrs,
new int[] { R.attr.doNotExpand, android.R.attr.hint, android.R.attr.textColorHint });
try {
mDoNotExpand = ta.getBoolean(R.attr.doNotExpand, false);
mHint = ta.getString(android.R.attr.hint);
mTextColorUnfocused = ta.getColorStateList(android.R.attr.textColorHint);
} finally {
ta.recycle();
}
mTextColorFocused = ThemeHelper.getAccentColor(context);
mTextPaint.setColor(mTextColorUnfocused.getColorForState(getDrawableState(), mTextColorUnfocused.getDefaultColor()));
mAnimator = ValueAnimator.ofFloat(0.f, 1.f);
mAnimator.setInterpolator(new LinearInterpolator());
mAnimator.setDuration(200);
mAnimator.addUpdateListener((ValueAnimator animation) -> {
mAnimState = (float) animation.getAnimatedValue();
invalidate();
});
updateTopMargin();
updateTextPositions();
}
示例5: updateMeasureState
import android.text.TextPaint; //導入方法依賴的package包/類
@Override
public void updateMeasureState(TextPaint p) {
p.setTypeface(mTypeface);
// Note: This flag is required for proper typeface rendering
p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
示例6: updateDrawState
import android.text.TextPaint; //導入方法依賴的package包/類
@Override
public void updateDrawState(TextPaint tp) {
tp.setTypeface(mTypeface);
// Note: This flag is required for proper typeface rendering
tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
示例7: CustomHintDialogCell
import android.text.TextPaint; //導入方法依賴的package包/類
public CustomHintDialogCell(Context context) {
super(context);
setBackgroundResource(R.drawable.list_selector);
imageView = new BackupImageView(context);
imageView.setRoundRadius(AndroidUtilities.dp(27));
addView(imageView, LayoutHelper.createFrame(43, 43, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 7, 0, 0));
nameTextView = new TextView(context);
nameTextView.setTextColor(0xff212121);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 9);
nameTextView.setMaxLines(2);
nameTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
nameTextView.setLines(2);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 6, 64, 6, 0));
if (countDrawable == null) {
countDrawable = getResources().getDrawable(R.drawable.dialogs_badge);
countDrawableGrey = getResources().getDrawable(R.drawable.dialogs_badge2);
countPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
countPaint.setColor(0xffffffff);
countPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
}
countPaint.setTextSize(AndroidUtilities.dp(11));
}
示例8: updateMeasureState
import android.text.TextPaint; //導入方法依賴的package包/類
@Override
public void updateMeasureState(TextPaint p) {
if (mTypeface != null) {
p.setTypeface(mTypeface);
}
if (textSize != 0) {
p.setTextSize(textSize);
}
p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
示例9: StaticLabelTextInputLayout
import android.text.TextPaint; //導入方法依賴的package包/類
public StaticLabelTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
mTextPaint.setTypeface(getTypeface());
mTextPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.abc_text_size_caption_material));
StyledAttributesHelper ta = StyledAttributesHelper.obtainStyledAttributes(context,
new int[] { android.R.attr.textColorHint });
mTextColorUnfocused = ta.getColor(android.R.attr.textColorHint, 0);
ta.recycle();
mTextColorFocused = ThemeHelper.getAccentColor(context);
mTextPaint.setColor(mTextColorUnfocused);
}
示例10: TabSwitcherDrawable
import android.text.TextPaint; //導入方法依賴的package包/類
private TabSwitcherDrawable(Resources resources, boolean useLight, Bitmap bitmap) {
super(resources, bitmap);
setTint(ApiCompatibilityUtils.getColorStateList(resources,
useLight ? R.color.light_mode_tint : R.color.dark_mode_tint));
mSingleDigitTextSize =
resources.getDimension(R.dimen.toolbar_tab_count_text_size_1_digit);
mDoubleDigitTextSize =
resources.getDimension(R.dimen.toolbar_tab_count_text_size_2_digit);
mTextPaint = new TextPaint();
mTextPaint.setAntiAlias(true);
mTextPaint.setTextAlign(Align.CENTER);
mTextPaint.setTypeface(Typeface.create("sans-serif-condensed", Typeface.BOLD));
mTextPaint.setColor(getColorForState());
}
示例11: init
import android.text.TextPaint; //導入方法依賴的package包/類
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(
attrs, R.styleable.RoundedLetterView, defStyle, 0);
if(a.hasValue(R.styleable.RoundedLetterView_rlv_titleText)){
mTitleText = a.getString(R.styleable.RoundedLetterView_rlv_titleText);
}
mTitleColor = a.getColor(R.styleable.RoundedLetterView_rlv_titleColor,DEFAULT_TITLE_COLOR);
mBackgroundColor = a.getColor(R.styleable.RoundedLetterView_rlv_backgroundColorValue,DEFAULT_BACKGROUND_COLOR);
mTitleSize = a.getDimension(R.styleable.RoundedLetterView_rlv_titleSize,DEFAULT_TITLE_SIZE);
a.recycle();
//Title TextPaint
mTitleTextPaint = new TextPaint();
mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
mTitleTextPaint.setTypeface(mFont);
mTitleTextPaint.setTextAlign(Paint.Align.CENTER);
mTitleTextPaint.setLinearText(true);
mTitleTextPaint.setColor(mTitleColor);
mTitleTextPaint.setTextSize(mTitleSize);
//Background Paint
mBackgroundPaint = new Paint();
mBackgroundPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
mBackgroundPaint.setStyle(Paint.Style.FILL);
mBackgroundPaint.setColor(mBackgroundColor);
mInnerRectF = new RectF();
}
示例12: GifBadge
import android.text.TextPaint; //導入方法依賴的package包/類
GifBadge(Context context) {
if (bitmap == null) {
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
final float density = dm.density;
final float scaledDensity = dm.scaledDensity;
final TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint
.SUBPIXEL_TEXT_FLAG);
textPaint.setTypeface(Typeface.create(TYPEFACE, TYPEFACE_STYLE));
textPaint.setTextSize(TEXT_SIZE * scaledDensity);
final float padding = PADDING * density;
final float cornerRadius = CORNER_RADIUS * density;
final Rect textBounds = new Rect();
textPaint.getTextBounds(GIF, 0, GIF.length(), textBounds);
height = (int) (padding + textBounds.height() + padding);
width = (int) (padding + textBounds.width() + padding);
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(true);
final Canvas canvas = new Canvas(bitmap);
final Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
backgroundPaint.setColor(BACKGROUND_COLOR);
canvas.drawRoundRect(0, 0, width, height, cornerRadius, cornerRadius,
backgroundPaint);
// punch out the word 'GIF', leaving transparency
textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
canvas.drawText(GIF, padding, height - padding, textPaint);
}
paint = new Paint();
}
示例13: updateDrawState
import android.text.TextPaint; //導入方法依賴的package包/類
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
ds.setUnderlineText(false);
}
示例14: updateDrawState
import android.text.TextPaint; //導入方法依賴的package包/類
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setTypeface(FontManager.instance().getTypeface());
ds.setUnderlineText(false);
}
示例15: buildSrcFromName
import android.text.TextPaint; //導入方法依賴的package包/類
@SuppressWarnings("ResourceAsColor")
private Bitmap buildSrcFromName(final String firstChar, int w, int h) {
if (w == Target.SIZE_ORIGINAL || w <= 0)
w = 80;
if (h == Target.SIZE_ORIGINAL || h <= 0)
h = 80;
final int size = Math.max(Math.min(Math.min(w, h), 220), 64);
final float fontSize = size * 0.4f;
log("firstChar:" + firstChar + " size:" + size + " fontSize:" + fontSize);
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565);
TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
paint.setAntiAlias(true);
paint.setDither(true);
paint.setColor(Color.WHITE);
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(fontSize);
paint.setTypeface(Typeface.SANS_SERIF);
// check ASCII
final int charNum = Character.getNumericValue(firstChar.charAt(0));
if (charNum > 0 && charNum < 177) {
Typeface typeface = getFont(getContext(), "Numans-Regular.otf");
if (typeface != null)
paint.setTypeface(typeface);
}
Rect rect = new Rect();
paint.getTextBounds(firstChar, 0, 1, rect);
int fontHeight = rect.height();
log(rect.toString());
int fontHalfH = fontHeight >> 1;
int centerX = bitmap.getWidth() >> 1;
int centerY = bitmap.getHeight() >> 1;
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(getBackgroundColor(firstChar));
canvas.drawText(firstChar, centerX, centerY + fontHalfH, paint);
return bitmap;
}