一种解决方案是使用keboardView.java代替android.inputmethodservice.KeyboardView。
您还需要将paint.setTypeface(Typeface.DEFAULT_BOLD)更改为paint.setTypeface(我的字体),并且必须将attrs.xml添加到您的项目中。
另一种解决方案:
改变应用程序内的字体样式。 创建一个名为的简单类FontOverride。
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();
}
}
}
将此类添加到您的代码中。
public final class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/Nastaleeq.ttf");
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/GeezEdit.ttf");
}
}
这里您可以看到添加了一些字体/字体名称。这些是可用于覆盖到键盘视图/标签中的外部字体文件。
添加此应用程序的名称到Android清单文件的应用程序名称
例如:
<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自定义键盘的输出字体吗?](https://stackoverflow.com/questions/34332318/can-i-change-the-output-font-of-an-android-custom -键盘) –