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

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

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

Typeface.defaultFromStyle介绍

暂无

代码示例

代码示例来源:origin: bluejamesbond/TextJustify-Android

protected void initPaint(Paint paint) {
  paint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
  paint.setTextSize(34);
  paint.setAntiAlias(true);
}

代码示例来源:origin: rmtheis/android-ocr

@Override
 protected synchronized void onPostExecute(Boolean result) {
  super.onPostExecute(result);
  
  if (result) {
   //Log.i(TAG, "SUCCESS");
   if (targetLanguageTextView != null) {
    targetLanguageTextView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL), Typeface.NORMAL);
   }
   textView.setText(translatedText);
   textView.setVisibility(View.VISIBLE);
   textView.setTextColor(activity.getResources().getColor(R.color.translation_text));

   // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
   int scaledSize = Math.max(22, 32 - translatedText.length() / 4);
   textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

  } else {
   Log.e(TAG, "FAILURE");
   targetLanguageTextView.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC);
   targetLanguageTextView.setText("Unavailable");

  }
  
  // Turn off the indeterminate progress indicator
  if (progressView != null) {
   progressView.setVisibility(View.GONE);
  }
 }
}

代码示例来源:origin: facebook/facebook-android-sdk

try {
  setTextSize(TypedValue.COMPLEX_UNIT_PX, a.getDimensionPixelSize(0, 0));
  setTypeface(Typeface.defaultFromStyle(a.getInt(1, Typeface.BOLD)));
  setText(a.getString(2));
} finally {

代码示例来源:origin: rmtheis/android-ocr

translationLanguageTextView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL), Typeface.NORMAL);
translationLanguageTextView.setVisibility(View.VISIBLE);

代码示例来源:origin: facebook/TextLayoutBuilder

/**
 * Sets a text style for the layout.
 *
 * @param style The text style for the layout
 * @return This {@link TextLayoutBuilder} instance
 */
public TextLayoutBuilder setTextStyle(int style) {
 return setTypeface(Typeface.defaultFromStyle(style));
}

代码示例来源:origin: chiuki/advanced-textview

@Override
public void draw(Canvas canvas) {
 int size = (int) -ascent;
 // Draw the circle
 paint.setStyle(Paint.Style.FILL);
 paint.setColor(Color.YELLOW);
 canvas.drawCircle(size/2, size/2, size/2 , paint);
 // Draw the ring
 paint.setStyle(Paint.Style.STROKE);
 paint.setColor(Color.RED);
 float ringWidth = size / 10;
 paint.setStrokeWidth(ringWidth);
 canvas.drawCircle(size/2, size/2, size/2 - ringWidth/2, paint);
 // Draw the text
 float ratio = 0.4f;
 paint.setStyle(Paint.Style.FILL);
 paint.setColor(Color.BLACK);
 paint.setTextAlign(Paint.Align.CENTER);
 paint.setTextSize(textSize * ratio);
 paint.setStrokeWidth(strokeWidth);
 paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
 int x = size / 2;
 int y = (int) (size/2 - ((descent + ascent)/2) * ratio);
 canvas.drawText(number, x, y, paint);
}

代码示例来源:origin: facebook/TextLayoutBuilder

builder.setTypeface(Typeface.defaultFromStyle(textStyle));

代码示例来源:origin: weexteam/weex-hackernews

public static void applyFontStyle(Paint paint, int style, int weight, String family) {
 int oldStyle;
 Typeface typeface = paint.getTypeface();
 if (typeface == null) {
  oldStyle = 0;
 } else {
  oldStyle = typeface.getStyle();
 }
 int want = 0;
 if ((weight == Typeface.BOLD)
  || ((oldStyle & Typeface.BOLD) != 0 && weight == WXStyle.UNSET)) {
  want |= Typeface.BOLD;
 }
 if ((style == Typeface.ITALIC)
  || ((oldStyle & Typeface.ITALIC) != 0 && style == WXStyle.UNSET)) {
  want |= Typeface.ITALIC;
 }
 if (family != null) {
  typeface = getOrCreateTypeface(family, want);
 }
 if (typeface != null) {
  paint.setTypeface(Typeface.create(typeface, want));
 } else {
  paint.setTypeface(Typeface.defaultFromStyle(want));
 }
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

typeface = Typeface.defaultFromStyle(style);
textPaint.setTypeface(Typeface.defaultFromStyle(style));

代码示例来源:origin: facebook/TextLayoutBuilder

builder.setTypeface(Typeface.defaultFromStyle(textStyle));
} else {
 builder.setTypeface(null);

代码示例来源:origin: flipkart-incubator/proteus

@Override
 public void setString(T view, String value) {
  int typeface = ParseHelper.parseTextStyle(value);
  view.setTypeface(Typeface.defaultFromStyle(typeface));
 }
});

代码示例来源:origin: JadynAi/LoadingLovely

private Path getPath() {
    Path textPath = new Path();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    paint.setTextSize(120);
    paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD_ITALIC));
    String s = mEditText.getText().toString().length() <= 0 ? "cece" : mEditText.getText().toString();
    paint.getTextPath(s, 0, s.length(), 0, 200, textPath);
    textPath.close();
    return textPath;
  }
}

代码示例来源:origin: derry/delion

private TextView addLabel(LinearLayout certificateView, String label) {
  TextView t = new TextView(mContext);
  ApiCompatibilityUtils.setTextAlignment(t, View.TEXT_ALIGNMENT_VIEW_START);
  t.setPadding(mPadding, mPadding / 2, mPadding, 0);
  t.setText(label);
  t.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
  t.setTextColor(ApiCompatibilityUtils.getColor(mContext.getResources(),
      R.color.connection_info_popup_text));
  certificateView.addView(t);
  return t;
}

代码示例来源:origin: SiberiaDante/TitleLayout

private void settingTitle() {
  if (StringUtil.isEmpty(mTitle)) {
    mTvTitle.setVisibility(INVISIBLE);
  } else {
    mTvTitle.setVisibility(VISIBLE);
    mTvTitle.setText(mTitle);
    mTvTitle.setTypeface(Typeface.defaultFromStyle(mTitleStyle));
    mTvTitle.setTextSize(TransitionTools.px2sp(mContext, mTitleSize));
    mTvTitle.setTextColor(mTitleColor);
  }
}

代码示例来源:origin: SiberiaDante/TitleLayout

private void settingRightText() {
  if (StringUtil.isEmpty(mRightText)) {
    mTvRight.setVisibility(GONE);
  } else {
    mTvRight.setVisibility(VISIBLE);
    mIvRight.setVisibility(GONE);
    mTvRight.setText(mRightText);
    mTvRight.setTextSize(TransitionTools.px2sp(mContext, mRightTextSize));
    mTvRight.setTextColor(mRightTextColor);
    mTvRight.setPadding(mRightTextPaddingStart, 0, mRightTextPaddingEnd, 0);
    mTvRight.setTypeface(Typeface.defaultFromStyle(mRightTextStyle));
  }
}

代码示例来源:origin: androider/IOSDialog

public BottomSheetDialog(Context context) {
  this.mContext = context;
  WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
  display = windowManager.getDefaultDisplay();
  defaultBottomBtnStyle = new SheetItemTextStyle();
  defaultBottomBtnStyle.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

assertEquals(Typeface.BOLD_ITALIC, textPaint.getTypeface().getStyle());
PromptUtils.setTypeface(textPaint, Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD_ITALIC);
assertEquals(Typeface.BOLD_ITALIC, textPaint.getTypeface().getStyle());
PromptUtils.setTypeface(textPaint, Typeface.defaultFromStyle(Typeface.BOLD), Typeface.ITALIC);
assertEquals(Typeface.ITALIC, textPaint.getTypeface().getStyle());
PromptUtils.setTypeface(textPaint, Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD);
assertEquals(Typeface.BOLD, textPaint.getTypeface().getStyle());
PromptUtils.setTypeface(textPaint, Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC);
assertEquals(Typeface.ITALIC, textPaint.getTypeface().getStyle());
PromptUtils.setTypeface(textPaint, Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.BOLD);
assertEquals(Typeface.BOLD, textPaint.getTypeface().getStyle());

代码示例来源:origin: grzegorznittner/chanu

public static StringTexture newInstance(
    String text, float textSize, int color,
    float lengthLimit, boolean isBold) {
  TextPaint paint = getDefaultPaint(textSize, color);
  if (isBold) {
    paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
  }
  text = TextUtils.ellipsize(
      text, paint, lengthLimit, TextUtils.TruncateAt.END).toString();
  return newInstance(text, paint);
}

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

@Test
public void testGetTypeface() throws Exception {
  TextAttributes attributes = new TextAttributes();
  Typeface typeface = Typeface.defaultFromStyle(Typeface.NORMAL);
  attributes.typeface = typeface;
  assertEquals(typeface, attributes.getTypeface());
}

代码示例来源:origin: NASAWorldWind/WorldWindAndroid

@Test
public void testSetTypeface() throws Exception {
  TextAttributes attributes = new TextAttributes();
  Typeface typeface = Typeface.defaultFromStyle(Typeface.NORMAL);
  attributes.setTypeface(typeface);
  assertEquals(typeface, attributes.typeface);
}

相关文章