Learn ,How to use Custom Font in android.
- http://www.1001freefonts.com/d/7051/most_wasted.zip
- Create a folder named fonts inside assets folder
- Paste your font there.
If you are unable to locate asset folder then create one by following the following steps as shown in the image (right click the app folder)
- Create layout or your app “activity_main.xml”
</pre> <pre><?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000"> <TextView android:id="@+id/txtCustomFont" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#fd8b22" android:layout_centerInParent="true" android:textSize="50dp" android:text="Awesome"/> </RelativeLayout></pre> <pre>
- Now open your activity “MainActivity.java”, In onCreate() write
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = (TextView) findViewById(R.id.txtCustomFont); Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Mostwasted.ttf"); tv.setTypeface(font); }
- Bingo, now run your app.
Know more about assest: http://stackoverflow.com/questions/5583608/difference-between-res-and-assets-directories
December 17, 2015 at 10:42 am
followed every step but still not working
LikeLike
December 17, 2015 at 10:48 am
make sure you have written the code above inside onCreate() and the font inside fonts folder inside assets folder.
LikeLike
December 17, 2015 at 10:50 am
Hurry, I got my mistake, thanks to you.
LikeLiked by 2 people