Android4.1——Jelly Bean 的字体变化情况分析

Android 4.1带来了几种变体和Roboto风格等10种变体字体,并且它们都能被应用程序所使用。你的应用程序现在可以访问全系列的细体和长体字体。

所有可用的的Roboto变体字有:

  • 常规<Regular>
  • 斜体<Italic>
  • 粗体<Bold>
  • 粗斜体<Bold-italic>
  • 细体<Light>
  • 细斜体<Light-italic>
  • 常规长体<Condensed regular>
  • 长斜体<Condensed italic>
  • 长粗体<Condensed bold>
  • 长粗斜体<Condensed bold-italic>

4.1新增加的字体:

            Roboto-LightItalic.ttf

            Roboto-Light.ttf

      这两个字库是比较细,颜色比较轻一点 拉丁字库。

           AndroidEmoji.ttf

           DroidNaskh-Regular-SystemUI.ttf

           DroidSansArabic.ttf

           DroidSansDevanagari-Regular.ttf

           DroidSansTamil-Regular.ttf

           DroidSansTamil-Bold.ttf

  同事还多了一个XML文件:fallback_fonts-ja.xml


你可以通过新的fontFamily属性与textStyle属性结合,应用上面的任何一种字体fontFamily所支持的值有:

  • "scans-serif"为常规的Roboto字体
  • "scans-serif-light"为细体的Roboto字体

"scans-serif-condensed"为长体的Roboto字体

然后可以通过textStyle应用粗体和斜体,其值分别为"bold""italic"。你可以通过以下方法同时应用两种字体:android:textStyle="bold|italic"

你也可以使用Typeface.create()方法。例如,Typeface.create("sans-serif-light", Typeface.NORMAL)

下面将列举几个简单的编程例子:

(1)针对粗斜体字体 

      //粗斜体字体

       italic_bold=newTextView(this);

       italic_bold.setTextSize(20f);

       italic_bold.setText("Italic & Bold Font FYI");

       //设置字体颜色为黄色

       italic_bold.setTextColor(Color.YELLOW); 

       //设置字型为等宽字型,斜体字体

       italic_bold.setTypeface(Typeface.MONOSPACE,Typeface.BOLD_ITALIC);

        linearLayout.addView(italic_bold,newLinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 

2)针对中文仿“粗体”

       //针对Android字型的中文字体问题

       chinese=newTextView(this);

       chinese.setText("中文粗体显示效果");      

       //设置字体颜色

       chinese.setTextColor(Color.MAGENTA);

       chinese.setTextSize(20.0f);

       chinese.setTypeface(Typeface.DEFAULT_BOLD, Typeface.BOLD);

       //使用TextPaint的仿粗体设置setFakeBoldTexttrue。目前还无法支持仿斜体方法

       tp=chinese.getPaint();

       tp.setFakeBoldText(true);

        linearLayout.addView(chinese,newLinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

(3)自定义创建字型

  在assets文件目录下创建font目录,再将要使用的字库添加到font目录下,接着在原代码中:

        Typeface enFont1 = Typeface.createFromAsset(getAssets(), "font/DroidSansFallback.ttf");
        Typeface enFont2 = Typeface.createFromAsset(getAssets(), "font/HelveticaNeueOTS.ttf");
        Typeface enFont3 = Typeface.createFromAsset(getAssets(), "font/MYingHeiBold18030C.ttf");
        mTextView_EN1.setTypeface(enFont1);
        mTextView_EN2.setTypeface(enFont2);
        mTextView_EN3.setTypeface(enFont3); 

这样我们的app项目就是用了我们自己定义的字库了。。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值