Reputation: 103
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
?
Upvotes: 5
Views: 4186
Reputation: 726
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.
Upvotes: 0
Reputation: 447
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
Upvotes: 9