有没有办法在android lollipop中使用geomanist(自定义)字体.
但它适用于所有其他版本.
这是我的代码
在MyApplication类中
FontsOverrIDe.setDefaultFont(this, "DEFAulT", "geomanist-lightnew.ttf"); FontsOverrIDe.setDefaultFont(this, "MONOSPACE", "geomanist-lightnew.ttf"); FontsOverrIDe.setDefaultFont(this, "serif", "geomanist-lightnew.ttf"); FontsOverrIDe.setDefaultFont(this, "SANS_serif", "geomanist-lightnew.ttf");
public final class FontsOverrIDe {public static voID setDefaultFont(Context context, String staticTypefaceFIEldname, String FontAssetname) { final Typeface regular = Typeface.createFromAsset(context.getAssets(), FontAssetname); replaceFont(staticTypefaceFIEldname, regular);}protected static voID replaceFont(String staticTypefaceFIEldname, final Typeface newTypeface) { try { final FIEld staticFIEld = Typeface.class .getDeclaredFIEld(staticTypefaceFIEldname); staticFIEld.setAccessible(true); staticFIEld.set(null, newTypeface); } catch (NoSuchFIEldException e) { e.printstacktrace(); } catch (illegalaccessexception e) { e.printstacktrace(); }}}
谢谢
解决方法:
我使用这个Library,它在所有设备上运行良好
步:-
1)在你的gradle编译’com.github.balrampandey19:FontOnText:0.0.1’中添加这一行
2)像这样在资产文件夹中添加你的字体
3)然后用xml替换你的视图
<com.balram.library.FottextVIEw androID:ID="@+ID/vno_tv" . . androID:textSize="14sp" app:Font="regular.ttf" />
此行对于设置您想要的自定义字体很重要:Font =“regular.ttf”
你可以为buttons Edittext做同样的事情
要么
如果你想在整个应用程序中使用相同的“字体”,你可以关注this Guide here
总结以上是内存溢出为你收集整理的android – 自定义字体在棒棒糖中不起作用全部内容,希望文章能够帮你解决android – 自定义字体在棒棒糖中不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)