Vaibhav Mishra
Vaibhav Mishra

Reputation: 12122

forcing droid sans to use as font in application

I have an android application in which if user changes his/her system font through settings to some other font, it looks ugly, how can I force my application to use droid sans as default font or an individual element to use droid sans irrespective of user preference.

Upvotes: 2

Views: 3157

Answers (3)

aphoe
aphoe

Reputation: 2726

In styles.xml, go to your Base application theme definition and then force typeface to use sans. So it will be something like below

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:typeface">sans</item>
</style>

Upvotes: 0

vmayatskii
vmayatskii

Reputation: 144

Put font file to project '/assets' folder and use it this way:

    TextView text = (TextView) findViewById(R.id.some_text);
    text.setTypeface(Typeface.createFromAsset(getAssets(),
            "DroidSans.ttf"));

Upvotes: 2

Kristiono Setyadi
Kristiono Setyadi

Reputation: 5643

You can use the XML layout to set the font for your application via android:typeface. You can set it to normal, sans, serif, or monospace.

Upvotes: 4

Related Questions