How to create custom view in Android and apply the custom font from xml.

Create custom textview or edittext with custom fonts

Hello Friends, After searching hundreds of answers related to creating the customtextview or edittext I came up with my implementation to efficiently create custom view so that we don’t have to assign typeface from java code.

And I call it efficient because once I came to scenario related to creating multiple fragments inside FragmentStatePagerAdapter and I wasted days solving the problem of UI lagging and freezing.And then I came to know that the view is inflating the typeface in wrong way.

Lets start to Create custom textview or edittext with custom fonts.

First is your custom view class.It may be EditText or Button also.

Typeface Class to apply custom font to our view:

Be careful to put your font.ttf file inside main->assets->fonts->RobotoBold.ttf

content of values–> attrs.xml (imp)


Include the view in your xml file:

Take care of the app:CustomFont .This name matches the name set for the value we defin


Name of your font in values–> strings.xml file:

<!– Custom fonts text–>

You can get more idea about this custom view code from