本文整理了Java中android.graphics.Typeface
类的一些代码示例,展示了Typeface
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Typeface
类的具体详情如下:
包路径:android.graphics.Typeface
类名称:Typeface
暂无
代码示例来源:origin: PhilJay/MPAndroidChart
MyAdapter(Context context, List<ContentItem> objects) {
super(context, 0, objects);
mTypeFaceLight = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");
mTypeFaceRegular = Typeface.createFromAsset(context.getAssets(), "OpenSans-Regular.ttf");
}
代码示例来源: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: 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: 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: robolectric/robolectric
@Test
public void createFromAsset_shouldCreateTypeface() {
Typeface typeface =
Typeface.createFromAsset(
ApplicationProvider.getApplicationContext().getAssets(), "myFont.ttf");
assertThat(typeface.getStyle()).isEqualTo(Typeface.NORMAL);
assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("myFont.ttf");
assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.NORMAL);
}
代码示例来源: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: elye/loaderviewlibrary
@Override
public void setRectColor(Paint rectPaint) {
final Typeface typeface = getTypeface();
if (typeface != null && typeface.getStyle()== Typeface.BOLD ) {
rectPaint.setColor(darkerColorResource);
} else {
rectPaint.setColor(defaultColorResource);
}
}
代码示例来源:origin: bluejamesbond/TextJustify-Android
protected void initPaint(Paint paint) {
paint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
paint.setTextSize(34);
paint.setAntiAlias(true);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void createFromFile_withFile_shouldCreateTypeface() {
Typeface typeface = Typeface.createFromFile(fontFile);
assertThat(typeface.getStyle()).isEqualTo(Typeface.NORMAL);
assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("myFont.ttf");
}
代码示例来源:origin: sjwall/MaterialTapTargetPrompt
assertEquals(Typeface.NORMAL, textPaint.getTypeface().getStyle());
assertEquals(Typeface.BOLD, textPaint.getTypeface().getStyle());
assertEquals(Typeface.BOLD, textPaint.getTypeface().getStyle());
assertEquals(Typeface.ITALIC, textPaint.getTypeface().getStyle());
assertEquals(Typeface.ITALIC, textPaint.getTypeface().getStyle());
assertEquals(Typeface.BOLD_ITALIC, textPaint.getTypeface().getStyle());
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: 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: sjwall/MaterialTapTargetPrompt
typeface = Typeface.defaultFromStyle(style);
typeface = Typeface.create(typeface, style);
int typefaceStyle = typeface != null ? typeface.getStyle() : 0;
int need = style & ~typefaceStyle;
textPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
textPaint.setTypeface(Typeface.defaultFromStyle(style));
代码示例来源:origin: novoda/android-demos
private int hintStyle() {
Typeface tf = getTypeface();
int style = Typeface.NORMAL;
if (tf != null) {
style = tf.getStyle();
}
return style;
}
代码示例来源: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: robolectric/robolectric
@Test
public void createFromFile_withPath_shouldCreateTypeface() {
Typeface typeface = Typeface.createFromFile(fontFile.getPath());
assertThat(typeface.getStyle()).isEqualTo(Typeface.NORMAL);
assertThat(shadowOf(typeface).getFontDescription().getFamilyName()).isEqualTo("myFont.ttf");
assertThat(shadowOf(typeface).getFontDescription().getStyle()).isEqualTo(Typeface.NORMAL);
}
代码示例来源:origin: PhilJay/MPAndroidChart
public BarChartItem(ChartData<?> cd, Context c) {
super(cd);
mTf = Typeface.createFromAsset(c.getAssets(), "OpenSans-Regular.ttf");
}
代码示例来源: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: 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: chrisjenx/Calligraphy
private void apply(final Paint paint) {
final Typeface oldTypeface = paint.getTypeface();
final int oldStyle = oldTypeface != null ? oldTypeface.getStyle() : 0;
final int fakeStyle = oldStyle & ~typeface.getStyle();
if ((fakeStyle & Typeface.BOLD) != 0) {
paint.setFakeBoldText(true);
}
if ((fakeStyle & Typeface.ITALIC) != 0) {
paint.setTextSkewX(-0.25f);
}
paint.setTypeface(typeface);
}
}
代码示例来源: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 {
内容来源于网络,如有侵权,请联系作者删除!