最小APIレベルが14のアプリがあります。互換性のあるすべてのデバイスにデフォルトでRobotoフォントをインストールする必要があると考えるのは正しいですか?textViewフォントをRobotoまたはRobotoLightに設定すると、デフォルトで通常のサンセリフ書体になっているようです。
Robotoフォントをアセットとして含めずにRobotoを使用する方法はありますか?
Robotoフォントをアセットとして含めずにRobotoを使用する方法はありますか?
API11<でこれを行う他の方法はありません。
私は通常、ロボット書体用のカスタムTextViewを作成します。
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);
}
}
これで、次のようにレイアウトで使用できます。
<com.my.package.TextView_Roboto>
android:layout_width="..."
android:layout_height="..."
[...]
</com.my.package.TextView_Roboto>
もちろん、TextViewレイアウトを作成することもできます。1つはPreHC用、もう1つはHC以降用です(layoutおよびlayout-v11フォルダーを使用する必要があります)。<include>
これで、タグを使用して、レイアウトにTextViewを含めることができます。次に、これを使用してこれを行う必要があります。
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);
}
編集:
次のように、Android4.1以降からRobotoをネイティブに使用できます。
android:fontFamily="sans-serif" // roboto regular
android:fontFamily="sans-serif-light" // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed