Answer the question
In order to leave comments, you need to log in
Android connection Fonts?
Good afternoon, guys, how to connect fonts to the project, globally.
For example, connected in one place so that they apply to everyone?
Answer the question
In order to leave comments, you need to log in
public class FontChangeCrawler {
private Typeface typeface;
public FontChangeCrawler(Typeface typeface) {
this.typeface = typeface;
}
public FontChangeCrawler(AssetManager assets, String assetsFontFileName) {
typeface = Typeface.createFromAsset(assets, assetsFontFileName);
}
public void replaceFonts(ViewGroup viewTree) {
View child;
for (int i = 0; i < viewTree.getChildCount(); ++i) {
child = viewTree.getChildAt(i);
if (child instanceof ViewGroup) {
replaceFonts((ViewGroup)child);
}
else if (child instanceof TextView) {
((TextView) child).setTypeface(typeface);
}
}
}
}
public class MainActivity extends AppCompatActivity {
@Override
public void setContentView(View view) {
super.setContentView(view);
FontChangeCrawler fontChanger = new FontChangeCrawler(getAssets(), "fonts/myfont.otf");
fontChanger.replaceFonts((ViewGroup)this.findViewById(android.R.id.content));
}
}
Wait for Android O and support library 26.0.0 (beta1 is available), it is there in its normal form.
Or use the Calligraphy library.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question