0

I know we can use Textview.setTypeface to set a custom typeface (ttf file from assets folder) on a Textview programmatically but i wanted to know is there any way to take advantage of this feature in Android Studio's Edit Mode when we're developing the UI with XML ? I tried to extend Textview class and setting the custom typeface in constructor but the result in edit mode was the same. It's working perfect when you're running the app on a real device but it gives a better experience to developer when he is developing the layout and see the exact result at the same time.

Community
  • 1
  • 1

3 Answers3

1

i wanted to know is there any way to take advantage of this feature in Android Studio's Edit Mode when we're developing the UI with XML ?

Not in standard Android, as there is no XML attribute for associating an arbitrary Typeface. You can use a third-party library like Calligraphy that offers this.

setting the custom typeface in constructor but the result in edit mode was the same

The editor does not necessarily have access to the typeface and so therefore will not show it in the preview. Now, in theory, a custom widget could do something in isInEditMode() and attempt to handle this, but I have no idea how practical that would be.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Custom typefaces are not supported by the layout rendering library currently. You can star the issue to be notified of updates.

http://b.android.com/27321

Deepanshu
  • 806
  • 6
  • 6
0

There are many ways to use typeface correctly in android, you have to put your typeface file in assets folder under your main directly and can use it run-time.

Other simplest way is use default library to set typeface in your xml file. I have prefer this custom typeface library to set typeface to TextView, EditText, Button, CheckBox, RadioButton and AutoCompleteTextView and other wedget in android.

link: https://github.com/jaydipumaretiya/CustomTypeface/

I have found step by step information with images and code to use my typeface in android project.