Change the font of entire app all textview, including buttons and edittexts

4.1k views Asked by At

I want to change the app font to roboto. I have tried this link also.

But it is changing only the textview font, not changing the listview adapter XML font.

How do I change the entire app font to roboto?

2

There are 2 answers

0
Roon13 On BEST ANSWER

Put this in your style.xml

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

also you have to change this.

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

Developer site has provided information on this. Let me know the progress

0
Sachin Rao On

You can pass the content view / or any view group to this function and a typeface.

public void replaceFonts(ViewGroup viewTree, TypeFace typeface) {
    Stack<ViewGroup> stackOfViewGroup = new Stack<ViewGroup>();
    stackOfViewGroup.push(viewTree);
    while (!stackOfViewGroup.isEmpty()) {
        ViewGroup tree = stackOfViewGroup.pop();
        for (int i = 0; i < tree.getChildCount(); i++) {
            View child = tree.getChildAt(i);
            if (child instanceof ViewGroup) {
                // recursive call
                stackOfViewGroup.push((ViewGroup) child);
            }else if (child instanceof Button) {
              ((Button) child).setTypeface(typeface);
            }else if (child instanceof EditText) {
               ((EditText) child).setTypeface(typeface);
            } else if (child instanceof TextView) {
                // base case
                ((TextView) child).setTypeface(typeface);
            }
        }
    }
}

Or create a custom Button, EditText,TextView .and add it to view group. Search for FontTextView on Google.