Showing custom font or View in preview section of Android Studio XML

后端 未结 2 1549
陌清茗
陌清茗 2021-02-09 15:30

Is there any way to view custom fonts/views in the preview section of Android Studio?

I have used font-awesome as a custom typeface

2条回答
  •  广开言路
    2021-02-09 16:04

    Preview section loads custom views fine as long as these views are correctly written. You have to remember about all small details like draw/onDraw/dispatchDraw methods, measuring and layouting, setting correct theme, styling, providing editMode data, etc.

    The deal is that Android Studio has its own Context and Resources classes which are unable to perform certain things. For example these classes lack implementation of reading assets from assets folder and raw resources from raw folder.

    To load a custom font, you need assets folder which you don't have access to in Android Studio. Custom view should work, more or less.

提交回复
热议问题