android.graphics.Typeface.create()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(221)

本文整理了Java中android.graphics.Typeface.create()方法的一些代码示例,展示了Typeface.create()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Typeface.create()方法的具体详情如下:
包路径:android.graphics.Typeface
类名称:Typeface
方法名:create

Typeface.create介绍

暂无

代码示例

代码示例来源:origin: robinhood/ticker

/**
 * Sets the typeface size used by this view.
 *
 * @param typeface the typeface to use on the text.
 */
public void setTypeface(Typeface typeface) {
  if (textStyle == Typeface.BOLD_ITALIC) {
    typeface = Typeface.create(typeface, Typeface.BOLD_ITALIC);
  } else if (textStyle == Typeface.BOLD) {
    typeface = Typeface.create(typeface, Typeface.BOLD);
  } else if (textStyle == Typeface.ITALIC) {
    typeface = Typeface.create(typeface, Typeface.ITALIC);
  }
  textPaint.setTypeface(typeface);
  onTextPaintMeasurementChanged();
}

代码示例来源:origin: rey5137/material

/**
   * @param familyName if start with 'asset:' prefix, then load font from asset folder.
   * @return
   */
  public static Typeface load(Context context, String familyName, int style) {
    if(familyName != null && familyName.startsWith(PREFIX_ASSET))
      synchronized (sCachedFonts) {
        try {
          if (!sCachedFonts.containsKey(familyName)) {
            final Typeface typeface = Typeface.createFromAsset(context.getAssets(), familyName.substring(PREFIX_ASSET.length()));
            sCachedFonts.put(familyName, typeface);
            return typeface;
          }
        } catch (Exception e) {
          return Typeface.DEFAULT;
        }

        return sCachedFonts.get(familyName);
      }

    return Typeface.create(familyName, style);
  }
}

代码示例来源:origin: ZieIony/Carbon

private static Typeface loadRoboto(Context context, Roboto roboto) {
    // try to load asset
    try {
      Typeface t = Typeface.createFromAsset(context.getAssets(), roboto.getPath());
      pathCache.put(roboto.getPath(), t);
      familyStyleCache[roboto.getTextStyle()].put(roboto.getFontFamily(), t);
      return t;
    } catch (Exception e) {
    }

    // try system font
    Typeface t = Typeface.create(roboto.getFontFamily(), roboto.getTextStyle());
    if (t != null) {
      pathCache.put(roboto.getPath(), t);
      familyStyleCache[roboto.getTextStyle()].put(roboto.getFontFamily(), t);
      return t;
    }

    return null;
  }
}

代码示例来源:origin: airbnb/lottie-android

private Typeface typefaceForStyle(Typeface typeface, String style) {
  int styleInt = Typeface.NORMAL;
  boolean containsItalic = style.contains("Italic");
  boolean containsBold = style.contains("Bold");
  if (containsItalic && containsBold) {
   styleInt = Typeface.BOLD_ITALIC;
  } else if (containsItalic) {
   styleInt = Typeface.ITALIC;
  } else if (containsBold) {
   styleInt = Typeface.BOLD;
  }

  if (typeface.getStyle() == styleInt) {
   return typeface;
  }

  return Typeface.create(typeface, styleInt);
 }
}

代码示例来源:origin: naman14/Timber

private Builder() {
  text = "";
  color = Color.GRAY;
  textColor = Color.WHITE;
  borderThickness = 0;
  width = -1;
  height = -1;
  shape = new RectShape();
  font = Typeface.create("sans-serif-light", Typeface.NORMAL);
  fontSize = -1;
  isBold = false;
  toUpperCase = false;
}

代码示例来源:origin: hidroh/materialistic

PeekabooTouchHelperCallback(Context context) {
  super(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
  mDefaultTextColor = ContextCompat.getColor(context,
      AppUtils.getThemedResId(context, android.R.attr.textColorPrimary));
  mPaint.setTextSize(context.getResources().getDimensionPixelSize(R.dimen.text_size_small));
  mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
  mPadding = context.getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);
}

代码示例来源:origin: robolectric/robolectric

/** Returns a stub typeface immediately. */
 @Implementation
 public static Typeface getFontSync(FontRequest request) {
  return Typeface.create(request.getQuery(), Typeface.NORMAL);
 }
}

代码示例来源:origin: JakeWharton/butterknife

private static @Nullable Unbinder parseBindFont(Object target, Field field, View source) {
 BindFont bindFont = field.getAnnotation(BindFont.class);
 if (bindFont == null) {
  return null;
 }
 validateMember(field);
 int id = bindFont.value();
 int style = bindFont.style();
 Context context = source.getContext();
 Class<?> fieldType = field.getType();
 Object value;
 if (fieldType == Typeface.class) {
  Typeface font = ResourcesCompat.getFont(context, id);
  value = style != Typeface.NORMAL
    ? Typeface.create(font, style)
    : font;
 } else {
  throw new IllegalStateException(); // TODO
 }
 trySet(field, target, value);
 return Unbinder.EMPTY;
}

代码示例来源:origin: wdullaer/MaterialDateTimePicker

canvas.drawCircle(x, y + MINI_DAY_NUMBER_TEXT_SIZE - DAY_HIGHLIGHT_CIRCLE_MARGIN,
      DAY_HIGHLIGHT_CIRCLE_SIZE, mSelectedCirclePaint);
  mMonthNumPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
} else {
  mMonthNumPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
  mMonthNumPaint.setColor(mDisabledDayTextColor);
} else if (mSelectedDay == day) {
  mMonthNumPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
  mMonthNumPaint.setColor(mSelectedDayTextColor);
} else if (mHasToday && mToday == day) {

代码示例来源:origin: iSoron/uhabits

public void initialize(Context context, int amOrPm) {
  if (mIsInitialized) {
    Log.e(TAG, "AmPmCirclesView may only be initialized once.");
    return;
  }
  Resources res = context.getResources();
  mUnselectedColor = res.getColor(R.color.white);
  mSelectedColor = res.getColor(R.color.blue);
  mAmPmTextColor = res.getColor(R.color.ampm_text_color);
  mSelectedAlpha = SELECTED_ALPHA;
  String typefaceFamily = res.getString(R.string.sans_serif);
  Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
  mPaint.setTypeface(tf);
  mPaint.setAntiAlias(true);
  mPaint.setTextAlign(Align.CENTER);
  mCircleRadiusMultiplier =
      Float.parseFloat(res.getString(R.string.circle_radius_multiplier));
  mAmPmCircleRadiusMultiplier =
      Float.parseFloat(res.getString(R.string.ampm_circle_radius_multiplier));
  String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
  mAmText = amPmTexts[0];
  mPmText = amPmTexts[1];
  setAmOrPm(amOrPm);
  mAmOrPmPressed = -1;
  mIsInitialized = true;
}

代码示例来源:origin: wdullaer/MaterialDateTimePicker

mMonthTitlePaint.setAntiAlias(true);
mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
mMonthTitlePaint.setColor(mDayTextColor);
mMonthTitlePaint.setTextAlign(Align.CENTER);
mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
mMonthDayLabelPaint.setColor(mMonthDayTextColor);
mMonthTitlePaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.BOLD));
mMonthDayLabelPaint.setStyle(Style.FILL);
mMonthDayLabelPaint.setTextAlign(Align.CENTER);

代码示例来源:origin: wangdan/AisenWeiBo

public void initialize(Context context, int amOrPm) {
  if (mIsInitialized) {
    Log.e(TAG, "AmPmCirclesView may only be initialized once.");
    return;
  }
  Resources res = context.getResources();
  mWhite = res.getColor(R.color.comm_white);
  mAmPmTextColor = res.getColor(R.color.ampm_text_color);
  mBlue = Utils.resolveColor(getContext(), R.attr.themeColor, res.getColor(R.color.comm_blue));
  String typefaceFamily = res.getString(R.string.sans_serif);
  Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
  mPaint.setTypeface(tf);
  mPaint.setAntiAlias(true);
  mPaint.setTextAlign(Align.CENTER);
  mCircleRadiusMultiplier =
      Float.parseFloat(res.getString(R.string.circle_radius_multiplier));
  mAmPmCircleRadiusMultiplier =
      Float.parseFloat(res.getString(R.string.ampm_circle_radius_multiplier));
  String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
  mAmText = amPmTexts[0];
  mPmText = amPmTexts[1];
  setAmOrPm(amOrPm);
  mAmOrPmPressed = -1;
  mIsInitialized = true;
}

代码示例来源:origin: xinghongfei/LookLook

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);
    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
      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();
}

代码示例来源:origin: wangdan/AisenWeiBo

mMonthTitlePaint.setAntiAlias(true);
mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
mMonthTitlePaint.setColor(mDayTextColor);
mMonthTitlePaint.setTextAlign(Align.CENTER);
mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
mMonthDayLabelPaint.setColor(mDayTextColor);
mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
mMonthDayLabelPaint.setStyle(Style.FILL);
mMonthDayLabelPaint.setTextAlign(Align.CENTER);

代码示例来源:origin: pchmn/MaterialChipsInput

/**
 * Constructor for <code>LetterTileProvider</code>
 *
 * @param context The {@link Context} to use
 */
public LetterTileProvider(Context context) {
  final Resources res = context.getResources();
  mPaint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
  mPaint.setColor(Color.WHITE);
  mPaint.setTextAlign(Paint.Align.CENTER);
  mPaint.setAntiAlias(true);
  mColors = res.obtainTypedArray(R.array.letter_tile_colors);
  mTileLetterFontSize = res.getDimensionPixelSize(R.dimen.tile_letter_font_size);
  //mDefaultBitmap = BitmapFactory.decodeResource(res, android.R.drawable.);
  mDefaultBitmap = drawableToBitmap(ContextCompat.getDrawable(context, R.drawable.ic_person_white_24dp));
  mWidth = res.getDimensionPixelSize(R.dimen.letter_tile_size);
  mHeight = res.getDimensionPixelSize(R.dimen.letter_tile_size);
}

代码示例来源:origin: ZieIony/Carbon

public static Typeface getTypeface(Context context, String fontFamily, int textStyle) {
  // get from cache
  Typeface t = familyStyleCache[textStyle].get(fontFamily);
  if (t != null)
    return t;
  // Roboto?
  for (Roboto style : Roboto.values()) {
    if (style.getFontFamily().equals(fontFamily) && style.getTextStyle() == textStyle) {
      t = loadRoboto(context, style);
      if (t != null)
        return t;
    }
  }
  // load from system res
  t = Typeface.create(fontFamily, textStyle);
  if (t != null) {
    familyStyleCache[textStyle].put(fontFamily, t);
    return t;
  }
  return Typeface.DEFAULT;
}

代码示例来源:origin: wdullaer/MaterialDateTimePicker

Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
mPaint.setTypeface(tf);
mPaint.setAntiAlias(true);

代码示例来源:origin: robolectric/robolectric

@Test
public void create_withFamily_shouldCreateTypeface() {
 Typeface typeface = Typeface.create(Typeface.create("roboto", Typeface.BOLD), Typeface.ITALIC);
 assertThat(typeface.getStyle()).isEqualTo(Typeface.ITALIC);
 assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("roboto");
 assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.ITALIC);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void create_withFamilyName_shouldCreateTypeface() {
 Typeface typeface = Typeface.create("roboto", Typeface.BOLD);
 assertThat(typeface.getStyle()).isEqualTo(Typeface.BOLD);
 assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("roboto");
 assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.BOLD);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void create_withoutFamily_shouldCreateTypeface() {
 Typeface typeface = Typeface.create((Typeface) null, Typeface.ITALIC);
 assertThat(typeface.getStyle()).isEqualTo(Typeface.ITALIC);
 assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo(null);
 assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.ITALIC);
}

相关文章