public void setTypeface(@NonNull Typeface newTypeface) {
   final Typeface oldTypeface = baseTextPaint.getTypeface();
   if (oldTypeface == newTypeface) {
     return;
   }
   baseTextPaint.setTypeface(newTypeface);
   textView.setBaseTextPaint(baseTextPaint);
 }
예제 #2
0
 private static String glyphMetricsString(TextPaint paint) {
   int metricsInt = paint.getFontMetricsInt(paint.getFontMetricsInt());
   float textSize = paint.getTextSize();
   float textScale = paint.getTextScaleX();
   float textSkew = paint.getTextSkewX();
   Typeface typeface = paint.getTypeface();
   return String.format("%i%.2f%.2f%.2f", metricsInt, textSize, textScale, textSkew);
 }
예제 #3
0
파일: Switch.java 프로젝트: 30962088/c11_as
  /**
   * Sets the typeface in which the text should be displayed on the switch. Note that not all
   * Typeface families actually have bold and italic variants, so you may need to use {@link
   * #setSwitchTypeface(Typeface, int)} to get the appearance that you actually want.
   *
   * @attr ref android.R.styleable#TextView_typeface
   * @attr ref android.R.styleable#TextView_textStyle
   */
  public void setSwitchTypeface(Typeface tf) {
    if (mTextPaint.getTypeface() != tf) {
      mTextPaint.setTypeface(tf);

      requestLayout();
      invalidate();
    }
  }
    public void initPaint(@NonNull TextPaint base) {
      paint.set(base);
      paint.setColor(color);
      paint.setAlpha(intAlpha());
      final Typeface typeface = base.getTypeface();
      if (typeface != null && typeface.getStyle() != Typeface.NORMAL) {
        paint.setTypeface(Typeface.create(typeface, Typeface.NORMAL));
      }

      // pre-calculate fixed height
      paint.setTextSize(Math.max(base.getTextSize() * DEF_SCALE, minTextSize));
      paint.getTextBounds("|", 0, 1, bounds);
      fixedTextHeight = bounds.height();

      // set real text size value
      paint.setTextSize(Math.max(base.getTextSize() * scale, minTextSize));

      initPaintShadow();
      invalidate(true);
    }