美文网首页
TextView 所有系统字体组合

TextView 所有系统字体组合

作者: Zig_Zag | 来源:发表于2019-03-30 12:04 被阅读0次

    参考:http://stackoverflow.com/questions/19691530/valid-values-for-androidfontfamily-and-what-they-map-to?answertab=votes#tab-top

    一共有12种组合

    Added in Android Jelly Bean (4.1) - API 16 :

    Regular (default):

    <item name="android:fontFamily">sans-serif</item>
    <item name="android:textStyle">normal</item> 
    

    Italic:

    <item name="android:fontFamily">sans-serif</item>
    <item name="android:textStyle">italic</item>
    

    Bold:

    <item name="android:fontFamily">sans-serif</item>
    <item name="android:textStyle">bold</item>
    

    Bold-italic:

    <item name="android:fontFamily">sans-serif</item>
    <item name="android:textStyle">bold|italic</item>
    

    Light:

    <item name="android:fontFamily">sans-serif-light</item>
    <item name="android:textStyle">normal</item>
    

    Light-italic:

    <item name="android:fontFamily">sans-serif-light</item>
    <item name="android:textStyle">italic</item>
    

    Thin :

    <item name="android:fontFamily">sans-serif-thin</item>
    <item name="android:textStyle">normal</item>
    

    Thin-italic :

    <item name="android:fontFamily">sans-serif-thin</item>
    <item name="android:textStyle">italic</item>
    

    Condensed regular:

    <item name="android:fontFamily">sans-serif-condensed</item>
    <item name="android:textStyle">normal</item>
    

    Condensed italic:

    <item name="android:fontFamily">sans-serif-condensed</item>
    <item name="android:textStyle">italic</item>
    

    Condensed bold:

    <item name="android:fontFamily">sans-serif-condensed</item>
    <item name="android:textStyle">bold</item>
    

    Condensed bold-italic:

    <item name="android:fontFamily">sans-serif-condensed</item>
    <item name="android:textStyle">bold|italic</item>
    

    Added in Android Lollipop (v5.0) - API 21 :

    Medium:

    <item name="android:fontFamily">sans-serif-medium</item>
    <item name="android:textStyle">normal</item>
    

    Medium-italic:

    <item name="android:fontFamily">sans-serif-medium</item>
    <item name="android:textStyle">italic</item>
    

    Black:

    <item name="android:fontFamily">sans-serif-black</item>
    <item name="android:textStyle">italic</item>
    

    具体样式如下:

    image

    代码中动态设置

    方法1 :只单纯设置粗体和正常

    //android中为textview动态设置字体为粗体
    TextView textView = (TextView)findViewById(R.id.textView);
    textView .setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    //设置为不加粗
    textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
    

    方法2 :同时搭配Fontfamily (此方法会覆盖方法1)

    //android中为textview动态设置字体为粗体
    TextView textView = (TextView)findViewById(R.id.textView);
    //其中"sans-serif"为上面介绍的fontfamily的字符串名字,
    //这个最好用一个string 资源映射,便于使用
    textView .setTypeface(Typeface.create("sans-serif",Typeface.BOLD));
    //同理 设置为不加粗
    textView.setTypeface(Typeface.create("sans-serif-thin",Typeface.NORMAL));
    

    相关文章

      网友评论

          本文标题:TextView 所有系统字体组合

          本文链接:https://www.haomeiwen.com/subject/veujbqtx.html