Android 字体替代对LayoutFlater没有影响
要覆盖整个应用程序的字体,我使用以下命令Android 字体替代对LayoutFlater没有影响,android,textview,layout-inflater,truetype,Android,Textview,Layout Inflater,Truetype,要覆盖整个应用程序的字体,我使用以下命令 public class TypefaceOverride { public static void override(Context context, String staticTypefaceFieldName, String fontAssetName) { final Typeface regular = Typeface.createFromAsset(context.getAssets(), fontAssetName);
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);
文本视图字体不起作用,我必须设置字体
txt.setTypeface(Typefaces.get(G.context, "iran_sans.ttf"));
此外,在线性布局中也有RecycleView,即膨胀但彩色效果的颜色错误(灰色!)
我该怎么办?该死的教育,为什么我的英语这么差 终于找到了解决办法 只需要添加上下文
LinearLayout product = (LinearLayout) G.inflater.cloneInContext(ActivityMain.this).inflate(R.layout.product, null);