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

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

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

Typeface.createFromAsset介绍

暂无

代码示例

代码示例来源: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: PhilJay/MPAndroidChart

public BarChartItem(ChartData<?> cd, Context c) {
  super(cd);
  mTf = Typeface.createFromAsset(c.getAssets(), "OpenSans-Regular.ttf");
}

代码示例来源:origin: PhilJay/MPAndroidChart

public LineChartItem(ChartData<?> cd, Context c) {
  super(cd);
  mTf = Typeface.createFromAsset(c.getAssets(), "OpenSans-Regular.ttf");
}

代码示例来源:origin: mikepenz/MaterialDrawer

@Override
public Typeface getTypeface(Context context) {
  if (typeface == null) {
    try {
      typeface = Typeface.createFromAsset(context.getAssets(), "fonts/" + TTF_FILE);
    } catch (Exception e) {
      return null;
    }
  }
  return typeface;
}

代码示例来源:origin: pockethub/PocketHub

/**
   * Returns typeface from name.
   */
  private static Typeface getTypeface(final Context context, final String name) {
    return Typeface.createFromAsset(context.getAssets(), name);
  }
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  tfRegular = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
  tfLight = Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf");
}

代码示例来源:origin: PhilJay/MPAndroidChart

public PieChartItem(ChartData<?> cd, Context c) {
  super(cd);
  mTf = Typeface.createFromAsset(c.getAssets(), "OpenSans-Regular.ttf");
  mCenterText = generateCenterText();
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Regular.ttf");
  return super.onCreateView(inflater, container, savedInstanceState);
}

代码示例来源:origin: PhilJay/MPAndroidChart

public RadarMarkerView(Context context, int layoutResource) {
  super(context, layoutResource);
  tvContent = findViewById(R.id.tvContent);
  tvContent.setTypeface(Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf"));
}

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

private Typeface getTypeFaceFromAsset(String fontPath) {
  if (fontPath != null) {
    return Typeface.createFromAsset(
        getContext().getAssets(), fontPath);
  }
  return null;
}

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

private Typeface getFontFamily(String fontFamily) {
 Typeface defaultTypeface = fontFamilies.get(fontFamily);
 if (defaultTypeface != null) {
  return defaultTypeface;
 }
 Typeface typeface = null;
 if (delegate != null) {
  typeface = delegate.fetchFont(fontFamily);
 }
 if (delegate != null && typeface == null) {
  String path = delegate.getFontPath(fontFamily);
  if (path != null) {
   typeface = Typeface.createFromAsset(assetManager, path);
  }
 }
 if (typeface == null) {
  String path = "fonts/" + fontFamily + defaultFontFileExtension;
  typeface = Typeface.createFromAsset(assetManager, path);
 }
 fontFamilies.put(fontFamily, typeface);
 return typeface;
}

代码示例来源:origin: GrenderG/Toasty

@Override
  public void onClick(View view) {
    Toasty.Config.getInstance()
        .setToastTypeface(Typeface.createFromAsset(getAssets(), "PCap Terminal.otf"))
        .allowQueue(false)
        .apply();
    Toasty.custom(MainActivity.this, R.string.custom_message, getResources().getDrawable(R.drawable.laptop512),
        Color.BLACK, Color.GREEN, Toasty.LENGTH_SHORT, true, true).show();
    Toasty.Config.reset(); // Use this if you want to use the configuration above only once
  }
});

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
  public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_line, container, false);

    chart = v.findViewById(R.id.lineChart1);

    chart.getDescription().setEnabled(false);

    chart.setDrawGridBackground(false);

    chart.setData(getComplexity());
    chart.animateX(3000);

    Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");

    Legend l = chart.getLegend();
    l.setTypeface(tf);

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setTypeface(tf);

    chart.getAxisRight().setEnabled(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(false);

    return v;
  }
}

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

@Test
 public void createFromAsset_throwsExceptionWhenFontNotFound() throws Exception {
  try {
   Typeface.createFromAsset(
     ApplicationProvider.getApplicationContext().getAssets(), "nonexistent.ttf");
   fail("Expected exception");
  } catch (RuntimeException expected) {
   // Expected
  }
 }
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View v = inflater.inflate(R.layout.frag_simple_pie, container, false);
  chart = v.findViewById(R.id.pieChart1);
  chart.getDescription().setEnabled(false);
  Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");
  chart.setCenterTextTypeface(tf);
  chart.setCenterText(generateCenterText());
  chart.setCenterTextSize(10f);
  chart.setCenterTextTypeface(tf);
  // radius of the center hole in percent of maximum radius
  chart.setHoleRadius(45f);
  chart.setTransparentCircleRadius(50f);
  Legend l = chart.getLegend();
  l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
  l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
  l.setOrientation(Legend.LegendOrientation.VERTICAL);
  l.setDrawInside(false);
  chart.setData(generatePieData());
  return v;
}

代码示例来源:origin: PhilJay/MPAndroidChart

chart.animateX(3000);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View v = inflater.inflate(R.layout.frag_simple_bar, container, false);
  // create a new chart object
  chart = new BarChart(getActivity());
  chart.getDescription().setEnabled(false);
  chart.setOnChartGestureListener(this);
  MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
  mv.setChartView(chart); // For bounds control
  chart.setMarker(mv);
  chart.setDrawGridBackground(false);
  chart.setDrawBarShadow(false);
  Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");
  chart.setData(generateBarData(1, 20000, 12));
  Legend l = chart.getLegend();
  l.setTypeface(tf);
  YAxis leftAxis = chart.getAxisLeft();
  leftAxis.setTypeface(tf);
  leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
  chart.getAxisRight().setEnabled(false);
  XAxis xAxis = chart.getXAxis();
  xAxis.setEnabled(false);
  // programmatically add the chart
  FrameLayout parent = v.findViewById(R.id.parentLayout);
  parent.addView(chart);
  return v;
}

代码示例来源:origin: PhilJay/MPAndroidChart

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
      WindowManager.LayoutParams.FLAG_FULLSCREEN);
  setContentView(R.layout.activity_colored_lines);
  setTitle("LineChartActivityColored");
  charts[0] = findViewById(R.id.chart1);
  charts[1] = findViewById(R.id.chart2);
  charts[2] = findViewById(R.id.chart3);
  charts[3] = findViewById(R.id.chart4);
  Typeface mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Bold.ttf");
  for (int i = 0; i < charts.length; i++) {
    LineData data = getData(36, 100);
    data.setValueTypeface(mTf);
    // add some transparency to the color with "& 0x90FFFFFF"
    setupChart(charts[i], data, colors[i % colors.length]);
  }
}

代码示例来源: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: 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());
}

相关文章