-2

I attempted to add a custom font to android studio but was unable to do so, i have just copied a font to the call folder as seen here:How to use custom font in Android Studio

1 Answers1

0
  1. Go to project folder
  2. Then app>src>main
  3. Create folder 'assets>fonts' into the main folder.
  4. Put your 'abc.ttf' into the fonts folder.

Then initialise your button and set the font in Oncreate if you are using Activity or in onViewCreated if you are using Fragment like below

Button myButton = (Button) findViewById(R.id.my_button_id);
TypeFace myFont = Typeface.createFromAsset(getAssets(),  "fonts/abc.ttf");
myButton.setTypeFace(myFont);
emilpmp
  • 1,716
  • 17
  • 32
  • When i tried to implement it, it gave me an issue which was: Error:(49, 9) error: cannot find symbol class TypeFace, why could this be happening? Im sorry i am a beginner, i dont understand. – Paranjaya Jain Dec 27 '17 at 08:20
  • Post the complete error that you received – emilpmp Dec 27 '17 at 09:33
  • TypeFace myFont = Typeface.createFromAsset(getAssets(), "fonts/Staubach.ttf"); ^ symbol: class TypeFace location: class MainActivity Note: C:\Users\Paranjaya Jain\AndroidStudioProjects\Call\app\src\main\java\com\example\paranjayajain\call\MainActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 error – Paranjaya Jain Dec 27 '17 at 09:48
  • Not sure about this error. Please check this post https://stackoverflow.com/questions/21601973/typeface-error-in-extended-baseadapter-class . If you are using a fragment, you can get the context or activity by getContext()/getActivity() methods – emilpmp Dec 27 '17 at 10:03