覆盖字体AllOver我使用的应用程序
public class TypefaceOverride {
public static void override(Context context, String staticTypefaceFieldName, String fontAssetName) {
final Typeface regular = Typeface.createFromAsset(context.getAssets(), fontAssetName);
replaceFont(staticTypefaceFieldName, regular);
}
private static void replaceFont(String staticTypefaceFieldName, final Typeface newTypeface) {
try {
final Field staticField = Typeface.class.getDeclaredField(staticTypefaceFieldName);
staticField.setAccessible(true);
staticField.set(null, newTypeface);
} catch (Exception e) {
e.printStackTrace();
}
}
}
然后在应用程序类
上使用此方法private void typeFace() {
TypefaceOverride.override(this, "DEFAULT", "iran_sans.ttf");
TypefaceOverride.override(this, "MONOSPACE", "iran_sans.ttf");
TypefaceOverride.override(this, "SERIF", "iran_sans.ttf");
TypefaceOverride.override(this, "SANS_SERIF", "iran_sans.ttf");
}
所有字体也会改变,但是当我
时 LinearLayout product = (LinearLayout) G.inflater.inflate(R.layout.product, null);
TextView txt = (TextView) product.findViewById(R.id.txt);
TextView字体不能获得效果我必须在其上设置字体
txt.setTypeface(Typefaces.get(G.context, "iran_sans.ttf"));
此外,LinearLayout中的RecycleView膨胀但 colorEdgeEffect 颜色错误(灰色!)
我该怎么办?
答案 0 :(得分:0)
https://developer.android.com/reference/android/view/LayoutInflater.html
只需添加上下文
LinearLayout product = (LinearLayout) G.inflater.cloneInContext(ActivityMain.this).inflate(R.layout.product, null);