【问题标题】:Android Black Roboto font styleAndroid Black Roboto 字体样式
【发布时间】:2015-05-26 12:55:28
【问题描述】:

我想在特定的 TextView 上应用 Black Roboto。我定义了一个样式,但我不知道如何设置 Black Roboto ?

在styles.xml文件中,我有这样的风格:

<style name="IntroTitle">
    <item name="android:textSize">48sp</item>
    <item name="android:textStyle">normal</item>
    <item name="android:textAllCaps">true</item>
</style>

在我的 layout.xml 中:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/title"
    style="@style/IntroTitle"
    android:textColor="@android:color/white"
    android:text="@string/intro_title_screen_1"/>

提前致谢

【问题讨论】:

  • 你有字体的 ttf 文件吗?

标签: android fonts roboto


【解决方案1】:

感谢大家的帮助。

Black Roboto 的正确答案是:

    <style name="IntroTitle">
        <item name="android:fontFamily">sans-serif-black</item>
        <item name="android:textSize">30sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textAllCaps">true</item>
    </style>

更多信息,请查看:android-sdk/platforms/android-/data/fonts/system_fonts.xml

【讨论】:

    【解决方案2】:

    将 fontFamily 属性添加到 TextView

    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/title"
    style="@style/IntroTitle"
    android:textColor="@android:color/white"
    android:text="@string/intro_title_screen_1"
    android:fontFamily="sans-serif" 
    android:textStyle="bold"/>
    

    android:fontFamily="sans-serif" 提供常规 Roboto,而 android:textStyle="bold" 使其变为粗体/黑色。

    但是,如果您的资产文件夹中有一个 Roboto-Black 字体文件并且想要将其应用到您的 TextView,您将不得不通过代码来完成。例如:

    Typeface type = Typeface.createFromAsset(getAssets(),"fonts/Roboto-Black.ttf"); 
    yourTextView.setTypeface(type);
    

    【讨论】:

      【解决方案3】:

      你需要设置

      android:fontFamily="sans-serif"
      

      为了在您的TextView 中使用 Roboto 字体。

      我认为您的意思是 Black Roboto 的粗体,因此您需要添加:

      android:textStyle="bold"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-07
        • 2014-01-28
        • 1970-01-01
        • 1970-01-01
        • 2016-12-01
        • 2012-02-14
        • 2017-01-17
        • 2015-06-15
        相关资源
        最近更新 更多