4

How can I change the entire typeface of my android application? previously I saw this post on github.The solution work fine only for devices with lower than api 21. For android 5 this method doesn't work even if we add a values-v21 folder with styles.xml separately.

This is my values-v21/styles.xml :

<resources>

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">

    </style>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:typeface">serif</item>
    </style>

</resources>
Hamidreza Salehi
  • 930
  • 2
  • 10
  • 22

2 Answers2

1
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
    <item name="android:buttonStyle">@style/RobotoButtonStyle</item>
</style>

<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
    <item name="android:fontFamily">sans-serif-light</item>
</style>

<style name="RobotoButtonStyle" parent="android:Widget.Holo.Button">
    <item name="android:fontFamily">sans-serif-light</item>
</style>

Then Apply theme to your app

<application
    android:theme="@style/AppTheme" >
</application>
Azim Ansari
  • 1,378
  • 11
  • 20
  • Doesn't work for me. By the way It seems only text views and buttons will be changed by this. I want to change the entire application typeface to one of my custom fonts – Hamidreza Salehi Jul 04 '15 at 09:36
  • [Look at this](http://stackoverflow.com/questions/2711858/is-it-possible-to-set-font-for-entire-application) They are trying to do something. Join them – Azim Ansari Jul 04 '15 at 09:48
0

One suggestion from is to create Custom Textview that extends android TextView.I am including sample code below

public class CustomTextView extends TextView{

public CustomTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
    // TODO Auto-generated constructor stub
}
public CustomTextView(Context context) {
    super(context);
    init();
    // TODO Auto-generated constructor stub
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
    // TODO Auto-generated constructor stub
}
private void init(){
    Typeface font_type=Typeface.createFromAsset(getContext().getAssets(), "font/ProximaNova_Reg.ttf");
    setTypeface(font_type);
}

}

And put your font in android asset/font folder.You can do it for Button,EditText etc.

Jinosh P
  • 341
  • 2
  • 8