大佬教程收集整理的这篇文章主要介绍了你能以编程方式更改android键盘文本字体吗?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import java.lang.reflect.Field; import android.content.Context; import android.graphics.Typeface; public final class FontsOverride { public static void setDefaultFont(Context context,String staticTypefaceFieldName,String fontAsset@R_618_8313@ { final Typeface regular = Typeface.createFromAsset(context.getAssets(),fontAsset@R_618_8313@; replaceFont(staticTypefaceFieldName,regular); } protected static void replaceFont(String staticTypefaceFieldName,final Typeface newTypefacE) { try { final Field staticField = Typeface.class .getDeclaredField(staticTypefaceField@R_618_8313@; staticField.setAccessible(true); staticField.set(null,newTypefacE); } catch (NoSuchFieldException E) { e.printStackTrace(); } catch (illegalaccessexception E) { e.printStackTrace(); } } }
public final class Application extends android.app.Application { @Override public void onCreate() { super.onCreate(); FontsOverride.setDefaultFont(this,"DEFAULT","fonts/GeezEdit.ttf"); FontsOverride.setDefaultFont(this,"MONOSPACE","fonts/GeezEdit.ttf"); /*FontsOverride.setDefaultFont(this,"MyFontAsset2.ttf"); FontsOverride.setDefaultFont(this,"SERIF","MyFontAsset3.ttf"); FontsOverride.setDefaultFont(this,"SANS_SERIF","MyFontAsset4.ttf");*/ } }
…..在这里你可以看到添加了一些fonts / fontname.这些是外部字体文件,您可以使用它们覆盖键盘视图/标签.
例
<application android:name=".Application" android:allowBACkup="false" android:installLOCATIOn="internalOnly" android:label="@String/ime_name" android:theme="@style/AppTheme" >.......
现在将上面的覆盖字体名称更新为您的样式.基本主题或您在清单应用程序中使用的主题.
例
<!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <item name="android:typeface">monospace</item> </style>
以上是大佬教程为你收集整理的你能以编程方式更改android键盘文本字体吗?全部内容,希望文章能够帮你解决你能以编程方式更改android键盘文本字体吗?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。