How to change android keyboard key font?

风流意气都作罢 提交于 2019-12-28 05:47:06

问题



How can I change the default font for keys of keyboard I am writing in android (Eclipse)?
Thank you


回答1:


One solution is to use keboardView.java instead of android.inputmethodservice.KeyboardView.

You also need to change paint.setTypeface(Typeface.DEFAULT_BOLD) to paint.setTypeface(my font) and you must add attrs.xml to your project.




回答2:


I found an answer : Implemented onDraw...

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

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



回答3:


if you are thinking to change the font style of android custom keyboard keys font style with an external .ttf font style then you can check my answer at a link answer to change the font style of key label of android custom keyboard and also to change the font style throughout the android application

this answer is verified by me personally so you can trust and check this.




回答4:


Well that's a very broad question. I can tell you how to set a different Typeface; how you work that into your keyboard application is up to you.

Place a font (.ttf or .otf) into your assets folder, and use the following code (assuming a font called "myfont.ttf" and a TextView with an id of "key"):

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

Reminder: Don't forget to check the license for the font you are using. Most do not allow redistribution without compensation. One freely licensed font you can use is Bitstream Vera Sans.



来源:https://stackoverflow.com/questions/4808468/how-to-change-android-keyboard-key-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!