android.widget.TextView.getTypeface()方法的使用及代码示例

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

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

TextView.getTypeface介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public void correctWidth(TextView textView, int desiredWidth)
{
  Paint paint = new Paint();
  Rect bounds = new Rect();

  paint.setTypeface(textView.getTypeface());
  float textSize = textView.getTextSize();
  paint.setTextSize(textSize);
  String text = textView.getText().toString();
  paint.getTextBounds(text, 0, text.length(), bounds);

  while (bounds.width() > desiredWidth)
  {
    textSize--;
    paint.setTextSize(textSize);
    paint.getTextBounds(text, 0, text.length(), bounds);
  }

  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}

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

if (view instanceof TextView) {
  TextView textView = (TextView)view;
  Typeface typeface = textView.getTypeface();
  if (typeface != null) {
    textStyle.put(TEXT_SIZE, textView.getTextSize());

代码示例来源:origin: square/assertj-android

public S hasTypeface(Typeface typeface) {
 isNotNull();
 Typeface actualTypeface = actual.getTypeface();
 assertThat(actualTypeface) //
   .overridingErrorMessage("Expected typeface <%s> but was <%s>.", typeface, actualTypeface) //
   .isSameAs(typeface);
 return myself;
}

代码示例来源:origin: eleme/UETool

@Override
  public List<Item> getAttrs(Element element) {
    List<Item> items = new ArrayList<>();
    TextView textView = ((TextView) element.getView());
    items.add(new TitleItem("TextView"));
    items.add(new EditTextItem("Text", element, EditTextItem.Type.TYPE_TEXT, textView.getText().toString()));
    items.add(new AddMinusEditItem("TextSize(sp)", element, EditTextItem.Type.TYPE_TEXT_SIZE, px2sp(textView.getTextSize())));
    items.add(new EditTextItem("TextColor", element, EditTextItem.Type.TYPE_TEXT_COLOR, Util.intToHexColor(textView.getCurrentTextColor())));
    List<Pair<String, Bitmap>> pairs = Util.getTextViewBitmap(textView);
    for (Pair<String, Bitmap> pair : pairs) {
      items.add(new BitmapItem(pair.first, pair.second));
    }
    items.add(new SwitchItem("IsBold", element, SwitchItem.Type.TYPE_IS_BOLD, textView.getTypeface() != null ? textView.getTypeface().isBold() : false));
    return items;
  }
}

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

@Test
public void canSetAndGetTypeface() throws Exception {
 Typeface typeface = Shadow.newInstanceOf(Typeface.class);
 textView.setTypeface(typeface);
 assertSame(typeface, textView.getTypeface());
}

代码示例来源:origin: JohnPersano/SuperToasts

this.mTextView.setTypeface(this.mTextView.getTypeface(), this.mStyle.messageTypefaceStyle);
this.mTextView.setTextColor(this.mStyle.messageTextColor);
this.mTextView.setTextSize(this.mStyle.messageTextSize);

代码示例来源:origin: k9mail/k-9

holder.from.setTypeface(Typeface.create(holder.from.getTypeface(), maybeBoldTypeface));
if (fragment.senderAboveSubject) {
  holder.from.setCompoundDrawablesWithIntrinsicBounds(
holder.subject.setTypeface(Typeface.create(holder.subject.getTypeface(), maybeBoldTypeface));
holder.subject.setText(subject);

代码示例来源:origin: roughike/BottomBar

@Test
@UiThreadTest
public void setTitleTypeface_UpdatesTypeface() {
  BottomBarTab tab = bottomBar.getCurrentTab();
  Typeface testTypeface = Typeface.createFromAsset(
      bottomBar.getContext().getAssets(), "fonts/GreatVibes-Regular.otf");
  assertNotEquals(testTypeface, tab.getTitleTypeFace());
  assertNotEquals(testTypeface, tab.getTitleView().getTypeface());
  bottomBar.setTabTitleTypeface(testTypeface);
  assertEquals(testTypeface, tab.getTitleTypeFace());
  assertEquals(testTypeface, tab.getTitleView().getTypeface());
}

代码示例来源:origin: chrisjenx/Calligraphy

if (TypefaceUtils.isLoaded(((TextView) view).getTypeface())) {
  return;

代码示例来源:origin: florent37/FiftyShadesOf

@Override
public void beforeStart() {
  super.beforeStart();
  this.textColor = view.getTextColors();
  this.darker = view.getTypeface() != null && view.getTypeface().isBold();
}

代码示例来源:origin: ISchwarz23/SortableTableView

@Override
  public View getHeaderView(final int columnIndex, final ViewGroup parentView) {
    final TextView textView = new TextView(getContext());

    if (columnIndex < headers.length) {
      textView.setText(headers[columnIndex]);
      textView.setGravity(gravity);
    }

    textView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    textView.setTypeface(textView.getTypeface(), typeface);
    textView.setTextSize(textSize);
    textView.setTextColor(textColor);
    textView.setSingleLine();
    textView.setEllipsize(TextUtils.TruncateAt.END);

    return textView;
  }
}

代码示例来源:origin: ISchwarz23/SortableTableView

@Override
public View getCellView(final int rowIndex, final int columnIndex, final ViewGroup parentView) {
  final TextView textView = new TextView(getContext());
  textView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
  textView.setTypeface(textView.getTypeface(), typeface);
  textView.setTextSize(textSize);
  textView.setTextColor(textColor);
  textView.setSingleLine();
  textView.setEllipsize(TextUtils.TruncateAt.END);
  try {
    final String textToShow = getItem(rowIndex)[columnIndex];
    textView.setText(textToShow);
    textView.setGravity(gravity);
  } catch (final IndexOutOfBoundsException e) {
    Log.w(LOG_TAG, "No Sting given for row " + rowIndex + ", column " + columnIndex + ". "
        + "Caught exception: " + e.toString());
    // Show no text
  }
  return textView;
}

代码示例来源:origin: willowtreeapps/Hyperion-Android

new ColorValue(view.getCurrentHintTextColor()),
    new ColorDrawable(view.getCurrentHintTextColor())));
attributes.add(new ViewAttribute<>("Typeface", view.getTypeface()));
attributes.add(new ViewAttribute<>("TextSize",
    attributeTranslator.translatePxToSp((int) view.getTextSize())));

代码示例来源:origin: adolfAn/FBReader_AS

/**
 * Sets the message typeface style of the {@value #TAG}.
 *
 * @param typeface {@link android.graphics.Typeface} int
 */
public void setTypefaceStyle(int typeface) {
  mTypefaceStyle = typeface;
  mMessageTextView.setTypeface(mMessageTextView.getTypeface(), typeface);
}

代码示例来源:origin: mylhyl/Android-CircleDialog

private void handleNegativeStyle() {
  mNegativeButton.setGravity(Gravity.CENTER);
  mNegativeButton.setText(mNegativeParams.text);
  mNegativeButton.setEnabled(!mNegativeParams.disable);
  mNegativeButton.setTextColor(mNegativeParams.disable ?
      mNegativeParams.textColorDisable : mNegativeParams.textColor);
  mNegativeButton.setTextSize(mNegativeParams.textSize);
  mNegativeButton.setHeight(mNegativeParams.height);
  mNegativeButton.setTypeface(mNegativeButton.getTypeface(), mNegativeParams.styleText);
}

代码示例来源:origin: mylhyl/Android-CircleDialog

private void handlePositiveStyle() {
  mPositiveButton.setGravity(Gravity.CENTER);
  mPositiveButton.setText(mPositiveParams.text);
  mPositiveButton.setEnabled(!mPositiveParams.disable);
  mPositiveButton.setTextColor(mPositiveParams.disable ?
      mPositiveParams.textColorDisable : mPositiveParams.textColor);
  mPositiveButton.setTextSize(mPositiveParams.textSize);
  mPositiveButton.setHeight(mPositiveParams.height);
  mPositiveButton.setTypeface(mPositiveButton.getTypeface(), mPositiveParams.styleText);
}

代码示例来源:origin: mylhyl/Android-CircleDialog

private void handleNegativeStyle() {
  mNegativeButton.setGravity(Gravity.CENTER);
  mNegativeButton.setText(mNegativeParams.text);
  mNegativeButton.setEnabled(!mNegativeParams.disable);
  mNegativeButton.setTextColor(mNegativeParams.disable ?
      mNegativeParams.textColorDisable : mNegativeParams.textColor);
  mNegativeButton.setTextSize(mNegativeParams.textSize);
  mNegativeButton.setHeight(mNegativeParams.height);
  mNegativeButton.setTypeface(mNegativeButton.getTypeface(), mNegativeParams.styleText);
}

代码示例来源:origin: mylhyl/Android-CircleDialog

private void handlePositiveStyle() {
  mPositiveButton.setGravity(Gravity.CENTER);
  mPositiveButton.setText(mPositiveParams.text);
  mPositiveButton.setEnabled(!mPositiveParams.disable);
  mPositiveButton.setTextColor(mPositiveParams.disable ?
      mPositiveParams.textColorDisable : mPositiveParams.textColor);
  mPositiveButton.setTextSize(mPositiveParams.textSize);
  mPositiveButton.setHeight(mPositiveParams.height);
  mPositiveButton.setTypeface(mPositiveButton.getTypeface(), mPositiveParams.styleText);
}

代码示例来源:origin: mylhyl/Android-CircleDialog

private void handleNeutralStyle() {
  mNeutralButton.setGravity(Gravity.CENTER);
  mNeutralButton.setText(mNeutralParams.text);
  mNeutralButton.setEnabled(!mNeutralParams.disable);
  mNeutralButton.setTextColor(mNeutralParams.disable ?
      mNeutralParams.textColorDisable : mNeutralParams.textColor);
  mNeutralButton.setTextSize(mNeutralParams.textSize);
  mNeutralButton.setHeight(mNeutralParams.height);
  mNeutralButton.setTypeface(mNeutralButton.getTypeface(), mNeutralParams.styleText);
}

代码示例来源:origin: Odoo-mobile/framework

private View generateView(String title, int res_id) {
  View view = LayoutInflater.from(this).inflate(R.layout.base_drawer_account_item,
      mDrawerAccountContainer, false);
  OControls.setGone(view, R.id.profile_url_text);
  ImageView icon = (ImageView) view.findViewById(R.id.profile_image);
  icon.setImageResource(res_id);
  icon.setColorFilter(OResource.color(this, R.color.body_text_2));
  TextView name = (TextView) view.findViewById(R.id.profile_name_text);
  name.setTypeface(name.getTypeface(), Typeface.BOLD);
  name.setText(title);
  return view;
}

相关文章

TextView类方法