【发布时间】:2016-04-29 02:31:26
【问题描述】:
尝试为按钮设置自定义字体时出现以下异常:java.lang.RuntimeException: native typeface cannot be made
我已经看过类似的问题,但他们的解决方案都没有奏效。
我的字体在 src/main 里面,文件结构看起来还不错。
这是文件结构:
这里是代码:
private void generateButtonListener(final Button btn,final String inputText) {
btn.setTypeface(Typeface.createFromAsset(getAssets(), "rb.ttf"));
btn.setOnClickListener(new android.view.View.OnClickListener() {
public void onClick(View view1) {
getCurrentInputConnection().commitText(inputText,1);
}
});
}
不确定是否重要,但我正在制作自定义键盘应用程序,因此我在 onCreateInputView 方法中的按钮上设置了此侦听器。像这样:
@Override
public View onCreateInputView() {
LayoutInflater lInflate = getLayoutInflater();
Resources res = getResources();
LinearLayout inputView = (LinearLayout) lInflate.inflate(R.layout.copypasta, null);
Button tab_navySeal = (Button) inputView.findViewById(R.id.tab_navySeal);
Button nSeal_1 = (Button) btnset_navyseal.findViewById(R.id.nSeal_1);
generateButtonListener(nSeal_1, res.getString(R.string.NStxt));
等等……
我似乎遵守了所有字体规则,有什么问题?
【问题讨论】:
标签: android android-fonts