Can you change the android keyboard text font programmatically? -


to frank title says really, i'm trying change input method service, keyboardview key font. of course.. it's not simple

android:keytextfont="sans-serif".

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 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();     }   } } 

add class code.

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, "monospace", "myfontasset2.ttf");     fontsoverride.setdefaultfont(this, "serif", "myfontasset3.ttf");     fontsoverride.setdefaultfont(this, "sans_serif", "myfontasset4.ttf");*/   } } 

..... here can see fonts/fontname added. these external font files can use overrite keyboard view/labels.

add application name android manifest file application name

example

 <application     android:name=".application"     android:allowbackup="false"     android:installlocation="internalonly"     android:label="@string/ime_name"     android:theme="@style/apptheme" >....... 

now update above overrited font name style. base theme or theme using @ manifest application.

example

 <!-- application theme. --> <style name="apptheme" parent="appbasetheme">     <item name="android:typeface">monospace</item> </style> 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -