android default keyboard layout -
i'm developing app nexus 7, , need edittext show keyboard view numbers , special characters. know can set layout edittext inputtype, problem if set inputtype="number" dialpad appears , not possible switch characters view. need (is customer's request) open keyboard layout shown when click on key "123" in bottom left. i've tried combinations of setrawinputtype , setinputtype no luck. combination shows dialpad
txtlinecode.setinputtype(inputtype.type_class_text); txtlinecode.setrawinputtype(inputtype.type_class_number);
this combination shows dialpad too
txtlinecode.setinputtype(inputtype.type_class_text); txtlinecode.setrawinputtype(inputtype.type_number_variation_normal|inputtype.type_class_number);
here screenshots better explain need
this default keyboard
this layout shown when click on "?123" , need show default
this layout shown if set inputtype="number", not allow switch lecters layout
by moment edittext prevalently numbers, should contains numbers, can do?
many thanks
i think found quite elegant solution: i've used drawable in textbox (in case drawableright), , i've assigned click listener on drawable executes switch between numeric , text mode. i'm able assign listener on drawable using little trick taken handling click events on drawable within edittext :
public class myedittextextends edittext { private drawable drawableright; private drawable drawableleft; private drawable drawabletop; private drawable drawablebottom; //your stuff here @override public void setcompounddrawables(drawable left, drawable top, drawable right, drawable bottom) { if (right != null) { drawableright = right; } if (left != null) { drawableleft = left; } super.setcompounddrawables(left, top, right, bottom); } view.onclicklistener _leftdrawableclicklistener = null; view.onclicklistener _rightdrawableclicklistener = null; public void setleftdrawableclicklistener(view.onclicklistener clicklistener) { _leftdrawableclicklistener = clicklistener; } public void setrightdrawableclicklistener(view.onclicklistener clicklistener) { _rightdrawableclicklistener = clicklistener; } @override public boolean ontouchevent(motionevent event) { if (event.getaction() == motionevent.action_down) { int x, y; rect bounds; x = (int) event.getx(); y = (int) event.gety(); // works left since container shares 0,0 origin bounds if (drawableleft != null) { bounds = drawableleft.getbounds(); if (bounds.contains(x - fuzz, y - fuzz)) { try { _leftdrawableclicklistener.onclick(this); } catch (exception e) { } if (consumeevent) { event.setaction(motionevent.action_cancel); return false; } } } else if (drawableright != null) { bounds = drawableright.getbounds(); if (x >= (this.getright() - bounds.width() - fuzz) && x <= (this.getright() - this.getpaddingright() + fuzz) && y >= (this.getpaddingtop() - fuzz) && y <= (this.getheight() - this.getpaddingbottom()) + fuzz) { try { _rightdrawableclicklistener.onclick(this); } catch (exception e) { } if (consumeevent) { event.setaction(motionevent.action_cancel); return false; } } } else if (drawabletop != null) { // not implemented yet } else if (drawablebottom != null) { // not implemented yet } } return super.ontouchevent(event); } @override protected void finalize() throws throwable { drawableright = null; drawablebottom = null; drawableleft = null; drawabletop = null; super.finalize(); } }
once custom edittext has been created, used code in activity
myedittext = (edittext) findviewbyid(r.id.myedittext); myedittext.setrightdrawableclicklistener(new onclicklistener() { @override public void onclick(view v) { if (myedittext.getinputtype() != inputtype.type_class_text) { myedittext.setinputtype(inputtype.type_class_text); myedittext.setrawinputtype(inputtype.type_class_text); myedittext.setcompounddrawableswithintrinsicbounds(0, 0, r.drawable.keyboard_123, 0); } else { myedittext.setrawinputtype(inputtype.type_class_number); myedittext.setinputtype(inputtype.type_class_number); myedittext.setcompounddrawableswithintrinsicbounds(0, 0, r.drawable.keyboard_abc, 0); } } });
this result: when edittext first shown appears this
and clicking on "abc" image becomes this
hope can someone
Comments
Post a Comment