android - 如何将资产中的字体用于自定义键盘
问题描述
如何在自定义键盘中使用资产中的字体?我的意思是在键盘的按键上使用字体。
它是我的键盘主要布局:
android.inputmethodservice.KeyboardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:keyTextColor="#ffff0000"
android:background="@drawable/themes"
android:keyBackground="@drawable/theme"
android:layout_alignParentBottom="true"
android:keyPreviewLayout="@layout/preview"
/>
我的字体名称是:
MyFont.tff
它是我的键盘活动:
package mr.saeed;
import android.inputmethodservice.*;
import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
import android.view.*;
import android.view.inputmethod.*;
public class saeedyaghi extends InputMethodService
implements OnKeyboardActionListener{
private KeyboardView kv;
private Keyboard keyboard;
private boolean caps = false;
@Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
switch(primaryCode){
case Keyboard.KEYCODE_DELETE :
ic.deleteSurroundingText(1, 0);
break;
case Keyboard.KEYCODE_SHIFT:
caps = !caps;
keyboard.setShifted(caps);
kv.invalidateAllKeys();
break;
case Keyboard.KEYCODE_DONE:
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
break;
default:
char code = (char)primaryCode;
if(Character.isLetter(code) && caps){
code = Character.toUpperCase(code);
}
ic.commitText(String.valueOf(code),1);
}
}
@Override
public void onPress(int primaryCode) {
}
@Override
public View onCreateInputView() {
kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard(this, R.xml.fa);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
return kv;
}
@Override
public void onRelease(int primaryCode) {
}
@Override
public void onText(CharSequence text) {
}
@Override
public void swipeDown() {
}
@Override
public void swipeLeft() {
}
@Override
public void swipeRight() {
}
@Override
public void swipeUp() {
}
}
提示:我询问并搜索了很多,我明白我应该在这里做键盘上的字体:
@Override
public View onCreateInputView() {
kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard(this, R.xml.fa);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
return kv;
字体系列不起作用,请不要提供它,伙计们,我想要一种实用且简单的方法,非常感谢。
解决方案
推荐阅读
- javascript - 带有 keydown 和 keyup 的 CSS 摆动动画
- dask - groupby 应用元参数后的未知 dask 数据帧索引
- pine-script - 对于 pinescript 策略,在信号发出后进入市场较晚
- c# - Serilog ASP .Net Core 不在 MacOS 中将日志写入文件但在 Windows 中工作
- fuse - 如何在 S3FS 中制造“传输端点未连接”问题(用于测试解决方法)
- java - 如何在我的项目中使用 SCA mvn 插件在 Fortify SCA 扫描中仅包含一个文件夹?
- flutter - Flutter:致命错误:找不到“Flutter/Flutter.h”文件
- c# - 如何在 App.config 中配置 serilog 和 applicationinsights?
- python - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 107654: invalid start byte Django 数据库更改为 MySQL
- sql - 选择最近的记录(带有到期日期)