使用Roboto字体的应用程序与最低API级别14 [英] Use Roboto font in app with minimum API level 14

查看:88
本文介绍了使用Roboto字体的应用程序与最低API级别14的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其最低API级别为14。我是正确的思维所有兼容设备应安装为默认Roboto字体?如果设置了一个TextView字体Roboto或Roboto点燃似乎默认为正常SANS字体。

有没有办法使用Roboto,而不包括Roboto字体作为一种资产?

解决方案
  

有没有办法使用Roboto,而不包括Roboto字体作为   资产?

没有出现这样的API 11 LT的没有别的办法。

我通常创建一个自定义的TextView机器人字体:

 公共类TextView_Roboto扩展TextView的{

        公共TextView_Roboto(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
                超(背景下,ATTRS,defStyle);
                的createFont();
        }

        公共TextView_Roboto(上下文的背景下,ATTRS的AttributeSet){
                超(背景下,ATTRS);
                的createFont();
        }

        公共TextView_Roboto(上下文的背景下){
                超(上下文);
                的createFont();
        }

        公共无效的createFont(){
                字体的字体= Typeface.createFromAsset(的getContext()getAssets(),robo_font.ttf);
                setTypeface(字体);
        }
}
 

现在你可以用它在你的布局是这样的:

 < com.my.package.TextView_Roboto>
  机器人:layout_width =...
  机器人:layout_height =...
  [...]
< /com.my.package.TextView_Roboto>
 

当然,你可以创建一个TextView布局。一为pre HC,一个HC及以上(你必须利用布局和布局-V11夹)。现在,您可以使用<包括> 标签,包括在你的布局TextView的。你只需要做到这一点利用这一则:

 如果(android.os.Build.VERSION.SDK_INT> = 11){
    TextView的TXT =(TextView中)findViewById(R.id.myTxtView);
}
其他{
    TextView_Roboto TXT =(TextView_Roboto)findViewById(R.id.myTxtView);
}
 

编辑:

您可以使用Roboto从本地的Andr​​oid 4.1及更高版本是这样的:

 安卓fontFamily中=无衬线// roboto常规
机器人:fontFamily中=无衬线光// roboto光
机器人:fontFamily中=无衬线,凝聚// roboto凝聚
 

I have an app whose minimum API level is 14. Am I correct in thinking all compatible devices should have Roboto font installed as default? If I set a textView font to Roboto or Roboto Light it seems to default to the normal sans typeface.

Is there a way to use Roboto without including the Roboto font as an asset?

解决方案

Is there a way to use Roboto without including the Roboto font as an asset?

No there is no other way of doing this for API 11<.

I usually create a custom TextView for the Robot typeface:

public class TextView_Roboto extends TextView {

        public TextView_Roboto(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);
                createFont();
        }

        public TextView_Roboto(Context context, AttributeSet attrs) {
                super(context, attrs);
                createFont();
        }

        public TextView_Roboto(Context context) {
                super(context);
                createFont();
        }

        public void createFont() {
                Typeface font = Typeface.createFromAsset(getContext().getAssets(), "robo_font.ttf");
                setTypeface(font);
        }
}

Now you can use it in your Layouts like this:

<com.my.package.TextView_Roboto>
  android:layout_width="..."
  android:layout_height="..."
  [...]
</com.my.package.TextView_Roboto>

Of course you can create a TextView layout. One for Pre HC, one for HC and above(You'll have to make use of the layout and layout-v11 folders). Now you can use the <include> tag to include the TextView in your Layout. You just have to do this use this then:

if (android.os.Build.VERSION.SDK_INT >= 11){
    TextView txt = (TextView) findViewById(R.id.myTxtView);
}
else{
    TextView_Roboto txt = (TextView_Roboto) findViewById(R.id.myTxtView);
}

Edit:

You can use Roboto natively from Android 4.1+ like this:

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed

这篇关于使用Roboto字体的应用程序与最低API级别14的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆