I am using android custom font lib Calligraphy https://github.com/chrisjenx/Calligraphy.
But there is no effect on textview. I am using the below code:
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" />
In attrs:
<resources>
<attr name="fontPath" format="string"/>
</resources>
In assets/font/gotham-book.ttf
Android O and AndroidX Library add support for Downloadable Fonts.
Remove the namespace from the TextView
.
<TextView
tools:context=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Touch Listner"
android:textSize="18sp"
fontPath="fonts/gotham-book.ttf" />
(Change app:fontPath
to fontPath
)
Annoyingly we can't resolve the auto-res namespace.
Create the class that extends Application, now and the following code in it. and declare it in manifest under application tag.
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/Roboto-ThinItalic.ttf")
.setFontAttrId(R.attr.fontPath)
.build()
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With