0

I'm starting in Android development and I got myself stocked in a problem...

I am trying to change the font of a Button in Android Studio, I've followed some tutorials closely but it didn't work.

Tutorials I followed:

Error trying to change font android studio

How to change the font on the TextView?

I don't receive any error message, it just doesn't work. Does anyone have any idea what I could be doing wrong?

Code:

    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/jua.ttf");

    Button Button = (Button) findViewById(R.id.Button)
    Button.setTypeface(font);

XML:

    <Button
        android:id="@+id/button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="@drawable/my_button_bg"
        android:text="Button"
        android:textColor="@android:color/white"
        android:textSize="15sp" />

Image of structure of folders:
Structure of folder - image

Jess felix
  • 23
  • 8
  • in latest android studio there is a separate folder for fonts in which you can define your custom fonts and add to the textview or button by setting font-family there – Devil10 Aug 14 '18 at 03:51
  • I'd recommend you the Calligraphy library to deal with the fonts. Its pretty easy to use and also lightweight. – Jaswant Singh Aug 14 '18 at 04:31

1 Answers1

0

Have you tried inserting your font in res/font directory and loading it as @font/myfont or R.font.myfont.

API 26 introduced this feature and you can find complete guide here: https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml

Qasim
  • 5,181
  • 4
  • 30
  • 51