15

アプリケーションにApiクラスがあります。Apiクラス内には、静的として設定されたカスタム フォントがあります。例えば:

public static Typeface fontShort;

public Api(Context c, Display d) {
    // I want to change this if user wants to keep using system font style or my custom style
    if (shouldKeepCurrent == true) {
        // Use system default font
        fontTitle =  // ???
    } else {
        // Use my costume font
        fontTitle = Typeface.createFromAsset(context.getAssets(), "fonts/custom.ttf");
    }       
}

ユーザーがカスタム フォントを使用したくない場合、デバイスのデフォルトおよび現在の書体を取得したい!

アクティビティ クラス:

TextView myView = (TextView) findViewById(R.id.myView);
// Change to custom font style or keep current font style
myView.setTypeface(Api.fontTitle);

何か案は?

4

1 に答える 1

40

以下を使用して、デフォルトの書体を取得できます。

if (keep_curren) {
    font_title = Typeface.DEFAULT;
}

指定したスタイルに基づいてデフォルトの書体を取得することもできます: Typeface.defaultFromStyle(int style).

詳細:こちら.

于 2013-08-17T22:39:31.080 に答える