如何更改android键盘键字体?

时间:2011-01-26 18:33:47

标签: android fonts keyboard


如何更改我在android(Eclipse)中编写的键盘键的默认字体?
谢谢

4 个答案:

答案 0 :(得分:4)

我找到了答案:已实施onDraw ...

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    try{
    onBufferDraw();
    }catch(Exception ex){

    }
    if (mBuffer!=null)
        canvas.drawBitmap(mBuffer, 0, 0, null);
}

答案 1 :(得分:4)

一种解决方案是使用keboardView.java代替android.inputmethodservice.KeyboardView

您还需要将paint.setTypeface(Typeface.DEFAULT_BOLD)更改为paint.setTypeface(my font),并且必须将attrs.xml添加到您的项目中。

答案 2 :(得分:2)

如果您正在考虑使用外部.ttf字体样式更改Android自定义键盘键字体样式的字体样式,那么您可以在链接中查看我的答案 answer to change the font style of key label of android custom keyboard and also to change the font style throughout the android application

这个答案已由我个人验证,因此您可以信任并检查此内容。

答案 3 :(得分:1)

那是一个非常广泛的问题。我可以告诉你如何设置不同的字体;你如何在键盘应用程序中使用它取决于你。

将字体(.ttf或.otf)放入资源文件夹,并使用以下代码(假设名为“myfont.ttf”的字体和ID为“key”的TextView):

Typeface myFont = Typeface.createFromAsset(getAssets(), "myfont.ttf");
TextView key = (TextView)findViewById(R.id.key);
key.setTypeface(myFont);

提醒:不要忘记检查您使用的字体的许可证。大多数人不允许重新分配而无需补偿。您可以使用的一种免费许可字体是Bitstream Vera Sans。