一種解決方案是使用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 -鍵盤) –