【问题标题】:sans-serif-thin is italic by default?sans-serif-thin 默认是斜体吗?
【发布时间】:2013-06-23 19:21:59
【问题描述】:

我正在尝试在我的一种布局中使用 roboto-thin 字体,但是当我将字体系列设置为“sans-serif-thin”时,字体默认为斜体,我无法强制它正常。

<TextView
    android:id="@+id/textLabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/firstLabel"
    android:fontFamily="sans-serif-thin"
    android:text="for this week"
    android:textSize="30sp"
    android:textStyle="normal"
    android:layout_marginTop="-15dp" />

谁能告诉我在布局中使用roboto-thin normal style字体的正确方法?

【问题讨论】:

    标签: android


    【解决方案1】:

    我在我的 4.2.2 和 2.2 设备上测试了您的代码,都显示正常字体,没有斜体。也许您在代码中的某处动态设置了不同的文本样式。

    【讨论】:

    • 嗯,你是对的。问题是,在图形布局设计器(或预览器,如果你愿意)它确实显示斜体样式。谢谢! :)
    • 我认为没有人能保证预览器的正确性。最安全的方法始终是在模拟器上进行测试,或者更好的是,尽可能在真实设备上进行测试。
    【解决方案2】:

    您应该在资产文件夹上创建文件夹字体并将您的字体 XX.ttf 放在那里。 然后,使用它:

    TextView txt = (TextView) findViewById(R.id.title);  
    Typeface font = Typeface.createFromAsset(getAssets(), "XX.ttf");  
    txt.setTypeface(font);  
    

    【讨论】:

    • 是的,如果我没记错的话,如果我想在 4.1 以下的设备上使用字体,情况就是这样。从 4.1 开始,默认包含 Roboto 字体。谢谢你的帮助! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多