Typeface always shows default font.
My fonts are stored in the assets/fonts. And I have tried to use other fonts, and to re-encode fonts. Also PixlUI library didn't solve the problem.
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
Typeface typeface = Typeface.createFromAsset(getAssets(),"fonts/OldEnglishFive.ttf");
button.setTypeface(typeface);
}
activity_main.xml
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="220dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:onClick="doSomething"
android:text="TEXT" />
If you haven't already tried using a font previously. I would suggest deleting your assets folder, creating a new assets folder inside your res folder and then move it back to where it was previously. Sometimes Android Studio doesn't accept the assets folder that gets built.
as shown here Runtime Exception: Font not found for every font i've tried - Android
also, I would reccomend creating a class that extends
Button
so that it'll automatically set your font for that widget if you assign the right XML to the button.An example would be:
and then in your xml you would only need to change
create an attrs.xml inside your values folder.
This would save you having to do
setTypeFace
everytime you would like a custom font on a button (or most other widgets, the same logic can be applied)