字体覆盖对 LayoutInflater 没有影响
Typeface Override have no effect on LayoutInflater
覆盖我使用的应用程序的所有字体
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();
}
}
}
然后应用这个方法class
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 That Inflated 但是 colorEdgeEffect 有错误的颜色(灰色!)
我该怎么办?
该死的教育! , 为什么我的英语这么差
终于找到解决方案
https://developer.android.com/reference/android/view/LayoutInflater.html
只需要添加上下文
LinearLayout product = (LinearLayout) G.inflater.cloneInContext(ActivityMain.this).inflate(R.layout.product, null);
覆盖我使用的应用程序的所有字体
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();
}
}
}
然后应用这个方法class
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 That Inflated 但是 colorEdgeEffect 有错误的颜色(灰色!)
我该怎么办?
该死的教育! , 为什么我的英语这么差 终于找到解决方案
https://developer.android.com/reference/android/view/LayoutInflater.html
只需要添加上下文
LinearLayout product = (LinearLayout) G.inflater.cloneInContext(ActivityMain.this).inflate(R.layout.product, null);