Reputation: 508
How can I change the default font for keys of keyboard I am writing in android (Eclipse)?
Thank you
Upvotes: 8
Views: 14842
Reputation: 508
I found an answer : Implemented onDraw...
override fun onDraw(canvas: Canvas) {
// super.onDraw(canvas) // commented not to draw default keyboard
if (!isInEditMode) {
onBufferDraw()
if (mBuffer != null)
canvas.drawBitmap(mBuffer!!, 0f, 0f, null)
}
}
private fun onBufferDraw() {
if (mBuffer == null) {
mBuffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
mCanvas = Canvas(mBuffer!!)
invalidateAllKeys()
}
// the rest of the draw function ...
Upvotes: 4
Reputation: 1884
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.
Upvotes: 2
Reputation:
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.
Upvotes: 4
Reputation: 134714
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.
Upvotes: 0