下面列出了android.text.TextPaint#setStrokeWidth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
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);
}
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);
}
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);
}
public Settings(Sushi slidr) {
this.slidr = slidr;
paintBar = new Paint();
paintBar.setAntiAlias(true);
paintBar.setStrokeWidth(2);
paintBar.setColor(colorBackground);
paintTextTop = new TextPaint();
paintTextTop.setAntiAlias(true);
paintTextTop.setStyle(Paint.Style.FILL);
paintTextTop.setColor(textColor);
paintTextTop.setTextSize(dpToPx(textSize));
paintTextBubble = new TextPaint();
paintTextBubble.setAntiAlias(true);
paintTextBubble.setStyle(Paint.Style.FILL);
paintTextBubble.setColor(Color.WHITE);
paintTextBubble.setStrokeWidth(2);
paintTextBubble.setTextSize(dpToPx(textSizeBubble));
paintBubble = new Paint();
paintBubble.setAntiAlias(true);
paintBubble.setStrokeWidth(3);
}
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);
}
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);
}
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);
}
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);
}
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);
}
public void init() {
TextPaint tp1 = this.borderText.getPaint();
tp1.setStrokeWidth(1.0f);
tp1.setStyle(Style.STROKE);
this.borderText.setTextColor(1275068416);
this.borderText.setGravity(getGravity());
}
public void init(Context mContext) {
TextPaint tp1 = this.borderText.getPaint();
tp1.setStrokeWidth(1.0f);
tp1.setStyle(Style.STROKE);
this.borderText.setTextColor(855638016);
this.borderText.setGravity(getGravity());
FontUtil.changeFontLanTing(mContext.getAssets(), this.borderText, this);
}
@Override
public void updateDrawState(TextPaint paint) {
final float newStrokeWidth = (mWeight / (UDFontWeight.WEIGHT_NORMAL_INT + 0.0f));
if (paint.getStyle() == Paint.Style.FILL) {
paint.setStyle(Paint.Style.FILL_AND_STROKE);
}
paint.setStrokeWidth(newStrokeWidth);
}
private Bitmap genBitmapFromStr(String str, TextPaint textPaint, float density) {
if (TextUtils.isEmpty(str)) {
return null;
}
Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
int h = (int) (Math.abs(fontMetrics.ascent) + Math.abs(fontMetrics.descent));
int w = (int) textPaint.measureText(str);
Bitmap bitmap = PhotoUtil.createBitmapOrNull(w, h, Bitmap.Config.ARGB_4444);
if (bitmap == null) {
return null;
}
Canvas canvas = new Canvas(bitmap);
// 描外层
textPaint.setColor(0xFF343434);
textPaint.setStrokeWidth(density * STROKE_WIDTH_DP + 0.5f); // 描边宽度
textPaint.setStyle(Paint.Style.FILL_AND_STROKE); //描边种类
textPaint.setFakeBoldText(true); // 外层text采用粗体
// textPaint.setShadowLayer(1, 0, 0, 0); //字体的阴影效果,可以忽略
canvas.drawText(str, 0, Math.abs(fontMetrics.ascent), textPaint);
// 描内层,恢复原先的画笔
textPaint.setColor(0xFFFFFFFF);
textPaint.setStrokeWidth(0);
textPaint.setStyle(Paint.Style.FILL_AND_STROKE);
textPaint.setFakeBoldText(false);
// textPaint.setShadowLayer(0, 0, 0, 0);
canvas.drawText(str, 0, Math.abs(fontMetrics.ascent), textPaint);
return bitmap;
}
public PrimitiveDrawer(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
paint = new TextPaint();
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
paint.setColor(0xffffffff);
paint.setStrokeWidth(1.f);
paint.setTextSize(35.f);
paint.setTextAlign(Paint.Align.LEFT);
}
@Override
public void updateDrawState(TextPaint tp) {
if (mDrawStroke) {
tp.setColor(mStrokeColor);
tp.setStrokeCap(Paint.Cap.ROUND);
tp.setStrokeWidth(mStrokeWidth);
tp.setStyle(Paint.Style.STROKE);
} else {
tp.setColor(mTextColor);
tp.setStyle(Paint.Style.FILL);
}
}
public Settings(Slidr slidr) {
this.slidr = slidr;
paintIndicator = new Paint();
paintIndicator.setAntiAlias(true);
paintIndicator.setStrokeWidth(2);
paintBar = new Paint();
paintBar.setAntiAlias(true);
paintBar.setStrokeWidth(2);
paintBar.setColor(colorBackground);
paintStep = new Paint();
paintStep.setAntiAlias(true);
paintStep.setStrokeWidth(5);
paintStep.setColor(colorStoppover);
paintTextTop = new TextPaint();
paintTextTop.setAntiAlias(true);
paintTextTop.setStyle(Paint.Style.FILL);
paintTextTop.setColor(textColor);
paintTextTop.setTextSize(textTopSize);
paintTextBottom = new TextPaint();
paintTextBottom.setAntiAlias(true);
paintTextBottom.setStyle(Paint.Style.FILL);
paintTextBottom.setColor(textColor);
paintTextBottom.setTextSize(textBottomSize);
paintBubbleTextCurrent = new TextPaint();
paintBubbleTextCurrent.setAntiAlias(true);
paintBubbleTextCurrent.setStyle(Paint.Style.FILL);
paintBubbleTextCurrent.setColor(Color.WHITE);
paintBubbleTextCurrent.setStrokeWidth(2);
paintBubbleTextCurrent.setTextSize(dpToPx(textSizeBubbleCurrent));
paintBubble = new Paint();
paintBubble.setAntiAlias(true);
paintBubble.setStrokeWidth(3);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(true);
ds.setStyle(Paint.Style.FILL_AND_STROKE);
PathEffect effects = new DashPathEffect(new float[]{1, 1}, 1);
ds.setPathEffect(effects);
ds.setStrokeWidth(2);
}
@Override
public void updateDrawState(TextPaint tp) {
tp.setStyle(Paint.Style.FILL_AND_STROKE);
//控制字体加粗的程度
tp.setStrokeWidth(dpToPx(context, f));
}
public SystemText(final String text, float size, boolean multiline) {
super(0, 0, 0, 0);
if (fontScale != fontScale) {
updateFontScale();
}
if (tf == null) {
if (Game.smallResScreen()) {
tf = Typeface.create((String) null, Typeface.BOLD);
oversample = 1;
} else {
tf = Typeface.create((String) null, Typeface.NORMAL);
oversample = 4;
}
}
size *= fontScale;
needWidth = multiline;
if (size == 0) {
throw new TrackedRuntimeException("zero sized font!!!");
}
float textSize = size * oversample;
if (!textPaints.containsKey(textSize)) {
TextPaint tx = new TextPaint();
tx.setTextSize(textSize);
tx.setStyle(Paint.Style.FILL_AND_STROKE);
tx.setHinting(Paint.HINTING_ON);
tx.setAntiAlias(true);
tx.setColor(Color.WHITE);
tx.setTypeface(tf);
TextPaint cp = new TextPaint();
cp.set(tx);
cp.setStyle(Paint.Style.FILL_AND_STROKE);
cp.setStrokeWidth(textSize * 0.2f);
cp.setColor(Color.BLACK);
cp.setAntiAlias(true);
textPaints.put(textSize, tx);
contourPaints.put(textSize, cp);
}
textPaint = textPaints.get(textSize);
contourPaint = contourPaints.get(textSize);
this.text(text);
texts.add(this);
}