私はAndroidカスタムフォントlib Calligraphy https://github.com/chrisjenx/Calligraphyを使用しています。
ただし、textviewへの影響はありません。以下のコードを使用しています:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(new CalligraphyContextWrapper(newBase));
}
}
In XML:
<TextView
tools:context=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Touch Listner"
android:textSize="18sp"
app:fontPath="fonts/gotham-book.ttf" />
属性で:
<resources>
<attr name="fontPath" format="string"/>
</resources>
assets / font / gotham-book.ttf内
Applicationを拡張するクラスと、その中の次のコードを作成します。そして、アプリケーションタグの下のマニフェストでそれを宣言します。
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/Roboto-ThinItalic.ttf")
.setFontAttrId(R.attr.fontPath)
.build()
);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加