How to change android keyboard key font?
Solution 1
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);
}
Solution 2
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.
Solution 3
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.
Comments
-
Heidar almost 2 years
How can I change the default font for keys of keyboard I am writing in android (Eclipse)?
Thank you -
Heidar over 13 yearsThank you for the response, but I am changing SoftKeyboard sample and I don't have any TextView to set Typeface to it. I just have an InputMethodService, a Keyboard, a Key and a KeyboardView.
-
Kevin Coppock over 13 yearsInteresting. Yeah, looking into it more, I don't see a way to modify it. However, apps like SwiftKey have a different typeface for their keys, so it's possible. Unfortunately I don't have a better answer for you.
-
Heidar over 13 yearsOne solution is to place an image for each key, but it's time consuming. Thank you anyway and please tell me if you found anything.
-
pm_labs about 11 yearsCould there be a better way? This approach looks like too much work and involves modifying a lot private vars/methods which could easily break in future Android versions. Might as well go through route of using images through "keyIcon" as it appears to be the cleaner way?
-
Heidar about 11 years@paul_sns I wished there was a better way but now I am used to it. I haven't seen too much change in newer versions.
-
Raykud over 9 yearscould you extend the answer please? I quite don't get how the onDraw would help change the font.
-
Fay007 almost 9 years@Heidar can u share a sample project where u have used this method to overcome the issue