I'm trying to change font all over my application. I couldn't find any solution, but I'm doing this activity by activity.
So I've written one function, which takes a view and if it's of certain view-type (text dervative), I set the text-size to my desired font size.
But I'm having one issue with TextInputLayout. I can't increase their font size no matter what.
My solution:
public static void setFontSize(View view, int fontSize) {
if (view == null) {
return;
}
// if (view instanceof TextInputLayout) {
// ??? what am i supposed to do here ???
// } else
if (view instanceof MaterialButton) {
((MaterialButton) view).setTextSize(fontSize);
} else if (view instanceof MaterialAutoCompleteTextView) {
((MaterialAutoCompleteTextView) view).setTextSize(fontSize);
} else if (view instanceof AutoCompleteTextView) {
((AutoCompleteTextView) view).setTextSize(fontSize);
} else if (view instanceof MaterialRadioButton) {
((MaterialRadioButton) view).setTextSize(fontSize);
} else if (view instanceof Button) {
((Button) view).setTextSize(fontSize);
} else if (view instanceof TextInputEditText) {
((TextInputEditText) view).setTextSize(fontSize);
} else if (view instanceof MaterialTextView) {
((MaterialTextView) view).setTextSize(fontSize);
} else if (view instanceof AppCompatTextView) {
((AppCompatTextView) view).setTextSize(fontSize);
} else if (view instanceof TextView) {
((TextView) view).setTextSize(fontSize);
} else if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
for (int i = 0; i < group.getChildCount(); i++) {
setFontSize(group.getChildAt(i), fontSize);
}
}
}
Somehow those labels are not being processed under this, so I can't set their type. Can you guys help me fix it?
I've already seen these solutions:
- https://stackoverflow.com/a/35203711/10305444
- https://stackoverflow.com/a/35409950/10305444
- https://stackoverflow.com/a/35738706/10305444
But they don't help me. (As they are providing static like solution, but I want to make it pure dynamic)