A CustomTextView class which removes the need for applying the custom fonts for each TextView
==============
Implementation:
-
Under
/res/values/
folder createattrs.xml
file with the following cotents:<?xml version="1.0" encoding="utf-8"?>
<declare-styleable name="CustomTextView"> <attr name="fontAssetName" format="string"/> </declare-styleable>
-
Add your desired fonts in
/assets
folder like "Politica XT.otf" font
==============
Usage:
Simply set the fontAssetName
attribute to an EXISITING font file name in your assets
folder
<?xml version="1.0" encoding="utf-8"?>
<com.my.app.CustomTextView
xmlns:custom="http://schemas.android.com/apk/res/com.my.app"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test text"
android:id="@+id/testcustomview"
custom:fontAssetName="Politica XT.otf"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:id="@+id/button"/>