I want to know how do I use an external font in Android Studio as there is no Assets folder. I have look for a helpful turtorial on internet but they all pretend to use Assets folder.
I created an asset folder myself in src/main
but Android Studio doesnt recognie getAssets()
.
To change font styles in GO Launcher, copy the TTF or OTF font files on your phone. Long press on the home screen and select GO Settings. Choose Font–>Select Font. Pick the font you want or tap Scan to add files stored on your device.
Put your font files (e.g customfont.tff and customfont_bold.tff) under the folder app>src>res>font> (Note: If it is not present, create font folder)
Additionally, create a file named fonts.xml inside the same folder with the following content:
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<font
app:fontStyle="normal"
app:fontWeight="700"
app:font="@font/customfont"/>
<font
app:fontStyle="normal"
app:fontWeight="700"
app:font="@font/customfont_bold"/>
</font-family>
Then, edit the file app>src>res>values>styles.xml to apply a default font for the entire app.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:fontFamily">@font/customfont</item>
</style>
If you want to change the font of an individual UI element:
<TextView
android:fontFamily="@font/customfont"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/black"
android:textSize="18sp"
android:text="Some text"
/>
NOTE: This method is valid for API Level 16+ (For more info: https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml)
If you have custom font then use following code:
TextView tv=(TextView)findViewById(R.id.custom);
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/Verdana.ttf");
tv.setTypeface(face);
Also place your font file in assets/fonts folder and follow the instructions from here.
NOTE: You have to make asset folder by yourself
Go on your Project: app-->src-->main
Create a assets folder like this:
|assets
|-----------------fonts
|-------------------font.ttf
|java
|res
AndroidManifest.xml
and then use
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/digital.ttf");
txtV.setTypeface(face);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With