【问题标题】:How do I use native Android OS 4.1 Roboto font in Eclipse, API 16 (fontFamily)如何在 Eclipse、API 16 (fontFamily) 中使用原生 Android OS 4.1 Roboto 字体
【发布时间】:2012-08-10 19:38:51
【问题描述】:

在 4.1 jellybean 中,Robot 已开始出现在整个系统 UI 中。我想在 Eclipse 中使用新属性“fontFamily”,如本页 Font Families 部分所述: http://developer.android.com/about/versions/android-4.1.html#UI

我们的目标是在所有支持它的设备上使用 Roboto(不包括在 /assets 中),并让字体在所有非 4.0+ 设备上优雅地降级为 Droid sans。再说一次,不想必须包含在我的 .apk 中,明白这很容易做到。

希望看到有关通过 API 16 成功使用 fontFamily 的示例代码或反馈。

【问题讨论】:

  • 如果你使用标准的TextViews,Android 会自动执行此操作,无需设置字体。

标签: android eclipse fonts android-4.2-jelly-bean font-family


【解决方案1】:

这很简单,因为旧版本的 Android 会忽略他们不理解的 xml 属性,您可以在文本视图或应用的样式上设置它。或者您可以在代码中手动设置它,但工作量更大:p

如果你使用的是普通版的 Roboto,你不需要做任何特别的事情,它是 4.0+ 中的默认设置(你可能需要一个基于全息的主题,我不记得了),以及 Roboto 粗体和使用 TextView 的 TextStyle 属性可以访问斜体。

在xml中

<TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:fontFamily="sans-serif-light"
      />

或者在代码中

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
    textView.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));         
}

【讨论】:

    猜你喜欢
    • 2012-11-12
    • 1970-01-01
    • 2013-11-08
    • 2015-07-16
    • 1970-01-01
    • 2017-10-02
    • 2019-01-15
    • 2020-12-27
    • 1970-01-01
    相关资源
    最近更新 更多