how to change key background of any key in Android soft keyboard -


i want have of keys in keyboard different others.

for example,like shift, delete, space key in below photo:

enter image description here

according reference documents google. can change key's background use "android:keybackground=@drawable/xxx" in "input.xml", change background of keys in keyboard.

although "android:keyicon" in qwerty.xml can have single key changed,but replace label. meanwhile, use "android:keyicon" , image can not cover entire key , image litte bit smaller key background.

what's correct way change background of keys?

it's not clear whether understand how create custom keyboard or not. in case don't, here's small downloadable project creates custom numeric keyboard. customkeyboardview class there or own custom keyboard class, add following method. overrides ondraw() method , draws background of key defined code 7 (in case "0") red , other keys blue.

@override public void ondraw(canvas canvas) {     super.ondraw(canvas);      list<key> keys = getkeyboard().getkeys();     (key key : keys) {                     if (key.codes[0] == 7) {             log.e("key", "drawing key code " + key.codes[0]);             drawable dr = (drawable) context.getresources().getdrawable(r.drawable.red_tint);             dr.setbounds(key.x, key.y, key.x + key.width, key.y + key.height);             dr.draw(canvas);          } else {             drawable dr = (drawable) context.getresources().getdrawable(r.drawable.blue_tint);             dr.setbounds(key.x, key.y, key.x + key.width, key.y + key.height);             dr.draw(canvas);         }                 } } 

tinted keys

in case, didn't use 9-patch images, simple 50% transparent square images , achieved effect existing buttons merely tinted colors wanted. more custom result, make drawables 9-patch images , following. note 2 keys icons don't render correctly because they're not defined 9-patch images , didn't take special effort make them scale example. didn't address use of different images/effects various states keys; others have shown how that.

@override public void ondraw(canvas canvas) {     // super.ondraw(canvas);      list<key> keys = getkeyboard().getkeys();     (key key : keys) {         if (key.codes[0] == 7) {             ninepatchdrawable npd                 = (ninepatchdrawable) context.getresources().getdrawable(r.drawable.red_key);             npd.setbounds(key.x, key.y, key.x + key.width, key.y + key.height);             npd.draw(canvas);          } else {             ninepatchdrawable npd                 = (ninepatchdrawable) context.getresources().getdrawable(r.drawable.blue_key);             npd.setbounds(key.x, key.y, key.x + key.width, key.y + key.height);             npd.draw(canvas);         }          paint paint = new paint();         paint.settextalign(paint.align.center);         paint.settextsize(48);         paint.setcolor(color.gray);          if (key.label != null) {             canvas.drawtext(key.label.tostring(), key.x + (key.width / 2),                             key.y + (key.height / 2), paint);         } else {             key.icon.setbounds(key.x, key.y, key.x + key.width, key.y + key.height);             key.icon.draw(canvas);         }     } }     

replaced keys


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -