android自定义数字键盘,安卓手机键盘数字

如果需要做一个定制化键盘(以外型为主)的创业,如何依靠代码,在公司自有的设计

1.自定义数字键盘

创新互联建站主营来安网站建设的网络公司,主营网站建设方案,成都app软件开发,来安h5小程序定制开发搭建,来安网站营销推广欢迎来安等地区企业咨询

2.切换到随机数字键盘

3.自定义确定和删除等键(向外抛出接口)

使用方法:

1.在项目build.gradle文件中添加jitpack,添加jitpcak就够了。allprojects{undefinedrepositories{undefinedjcenter()maven{url''}}}2.在module的build.gradle文件添加依赖compile'com.github.Simon986793021:NumberKeyboard:v1.0'3.在布局文件中添加布局android:id="@+id/keyboard_view"xmlns:android=""android:layout_width="match_parent"android:layout_height="wrap_content"android:focusable="true"android:paddingTop="0dp"android:focusableInTouchMode="true"android:keyBackground="@drawable/bg_keyboardview"android:keyPreviewOffset="0dp"android:keyTextColor="#000"android:shadowColor="#fff"android:shadowRadius="0.0"android:layout_alignParentBottom="true"/4.在MainActivity调用。editText=(EditText)findViewById(R.id.et_numberplate);changebutton=(Button)findViewById(R.id.bt_change_keyboard);finalOfoKeyboardkeyboard=newOfoKeyboard(MainActivity.this);//获取到keyboard对象changebutton.setOnClickListener(newView.OnClickListener(){undefined@OverridepublicvoidonClick(Viewv){undefinedkeyboard.attachTo(editText,true);//eiditext绑定keyboard,true表示随机数字}});editText.setOnClickListener(newView.OnClickListener(){undefined@OverridepublicvoidonClick(Viewv){undefinedkeyboard.attachTo(editText,false);//eiditext绑定keyboard,false表示普通数字键盘}});/*确定按钮*/keyboard.setOnOkClick(newOfoKeyboard.OnOkClick(){undefined@OverridepublicvoidonOkClick(){undefinedLog.i("","点击了确定");Toast.makeText(MainActivity.this,editText.getText().toString(),Toast.LENGTH_SHORT).show();}});//隐藏键盘按钮keyboard.setOnCancelClick(newOfoKeyboard.OnCancelClcik(){undefined@OverridepublicvoidonCancelClick(){undefinedToast.makeText(MainActivity.this,"隐藏键盘",Toast.LENGTH_SHORT).show();}});只需要这些简单的代码就能够实现一个自己定义的键盘了。实现过程1.新建一个keyboard布局在看这个代码之前需要了解keyboard的属性:不清楚属性,怎么画页面,不懂的请移步这篇博客在res新建一个xml文件,然后在xml新建一个keyboard.xml里面代码如下xmlns:android=""android:keyHeight="9%p"android:keyWidth="25%p"android:horizontalGap="0dp"android:codes="49"android:keyLabel="1"/android:codes="50"android:keyLabel="2"/android:codes="51"android:keyLabel="3"/android:codes="-5"android:keyHeight="18%p"android:keyEdgeFlags="right"android:isRepeatable="true"android:keyIcon="@drawable/icon_delete_32dp"/android:codes="52"android:keyLabel="4"/android:codes="53"android:keyLabel="5"/android:codes="54"android:keyLabel="6"/android:codes="55"android:keyLabel="7"/android:codes="56"android:keyLabel="8"/android:codes="57"android:keyLabel="9"/android:codes="-4"android:keyLabel="确定"android:keyEdgeFlags="right"android:keyHeight="18%p"/android:codes="46"android:keyLabel="."/android:codes="48"android:keyLabel="0"/android:codes="-3"android:keyIcon="@drawable/icon_hide_keyboard"/这个布局就是自己自定义键盘的布局实现,有了布局,显然是不够的。2.自定义KeyboardViewpackagecom.wind.keyboard;importandroid.content.Context;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.Paint;importandroid.graphics.Rect;importandroid.graphics.Typeface;importandroid.graphics.drawable.Drawable;importandroid.inputmethodservice.Keyboard;importandroid.inputmethodservice.KeyboardView;importandroid.util.AttributeSet;importandroid.util.Log;importjava.lang.reflect.Field;importjava.util.List;/***Createdbyzhangcongon2017/8/24.*/publicclassOfoKeyboardViewextendsKeyboardView{undefinedprivateContextcontext;privateKeyboardkeyboard;publicOfoKeyboardView(Contextcontext,AttributeSetattrs){undefinedsuper(context,attrs);this.context=context;Log.i("","构造函数被调用了");}/***重新画一些按键*/@OverridepublicvoidonDraw(Canvascanvas){undefinedsuper.onDraw(canvas);keyboard=this.getKeyboard();Listkeys=null;if(keyboard!=null){undefinedkeys=keyboard.getKeys();}if(keys!=null){undefinedfor(Keyboard.Keykey:keys){undefined//数字键盘的处理if(key.codes[0]==-4){undefineddrawKeyBackground(R.drawable.bg_keyboardview_yes,canvas,key);drawText(canvas,key);}}}}privatevoiddrawKeyBackground(intdrawableId,Canvascanvas,Keyboard.Keykey){undefinedDrawablenpd=context.getResources().getDrawable(drawableId);int[]drawableState=key.getCurrentDrawableState();if(key.codes[0]!=0){undefinednpd.setState(drawableState);}npd.setBounds(key.x,key.y,key.x+key.width,key.y+key.height);npd.draw(canvas);}privatevoiddrawText(Canvascanvas,Keyboard.Keykey){undefinedRectbounds=newRect();Paintpaint=newPaint();paint.setTextAlign(Paint.Align.CENTER);paint.setAntiAlias(true);paint.setColor(Color.WHITE);if(key.label!=null){undefinedStringlabel=key.label.toString();Fieldfield;if(label.length()1key.codes.length","attachTo");this.editText=editText;hideSystemSofeKeyboard(activity,editText);showSoftKeyboard();}privatevoidshowSoftKeyboard(){undefinedif(keyboard==null){undefinedkeyboard=newKeyboard(activity,R.xml.keyboard);}if(keyboardView==null){undefinedkeyboardView=(OfoKeyboardView)activity.findViewById(R.id.keyboard_view);}if(isRandom){undefinedrandomKeyboardNumber();}else{undefinedkeyboardView.setKeyboard(keyboard);}keyboardView.setEnabled(true);keyboardView.setPreviewEnabled(false);keyboardView.setVisibility(View.VISIBLE);keyboardView.setOnKeyboardActionListener(listener);}privateKeyboardView.OnKeyboardActionListenerlistener=newKeyboardView.OnKeyboardActionListener(){undefined@OverridepublicvoidonPress(intprimaryCode){undefined}@OverridepublicvoidonRelease(intprimaryCode){undefined}@OverridepublicvoidonKey(intprimaryCode,int[]keyCodes){undefinedEditableeditable=editText.getText();intstart=editText.getSelectionStart();if(primaryCode==Keyboard.KEYCODE_DELETE)//keycodes为-5{undefinedif(editable!=nulleditable.length()0){undefinedif(start0){undefinededitable.delete(start-1,start);}}}elseif(primaryCode==Keyboard.KEYCODE_CANCEL){undefinedhideKeyBoard();if(mCancelClick!=null){undefinedmCancelClick.onCancelClick();}}elseif(primaryCode==Keyboard.KEYCODE_DONE){undefinedhideKeyBoard();if(mOkClick!=null){undefinedmOkClick.onOkClick();}}else{undefinedLog.i("",primaryCode+"1");Log.i("",(char)primaryCode+"2");editable.insert(start,Character.toString((char)primaryCode));}}@OverridepublicvoidonText(CharSequencetext){undefined}@OverridepublicvoidswipeLeft(){undefined}@OverridepublicvoidswipeRight(){undefined}@OverridepublicvoidswipeDown(){undefined}@OverridepublicvoidswipeUp(){undefined}};publicinterfaceOnOkClick{undefinedvoidonOkClick();}publicinterfaceOnCancelClcik{undefinedvoidonCancelClick();}publicOnOkClickmOkClick;publicOnCancelClcikmCancelClick;publicvoidsetOnOkClick(OnOkClickonOkClick){undefinedthis.mOkClick=onOkClick;}publicvoidsetOnCancelClick(OnCancelClcikonCancelClick){undefinedthis.mCancelClick=onCancelClick;}privatevoidhideKeyBoard(){undefinedintvisibility=keyboardView.getVisibility();if(visibility==KeyboardView.VISIBLE){undefinedkeyboardView.setVisibility(KeyboardView.GONE);}}privatebooleanisNumber(Stringstr){undefinedStringwordstr="0123456789";returnwordstr.contains(str);}privatevoidrandomKeyboardNumber(){undefinedListkeyList=keyboard.getKeys();//查找出0-9的数字键ListnewkeyList=newArrayList();for(inti=0;i

回答于 2022-04-01

请问怎么制作一个Android的虚拟数字键盘。

手机系统最好是开发版,稳定版必须先root,可以自己root(另找教程),也可以刷成开发版。我的手机系统是MIUI4.10.31(开发版),可以在“系统更新”查看,具有root功能。

安装RE管理器和Root Explorer。小米4自带应用商店没有这两个,所以我先下了豌豆荚,再安装这两个app。RE管理器需要下载两个APP后才能启用。

Root Explorer获取root权限。开发版小米4自带的“安全中心”——ROOT权限管理——Root Explorer,获取root权限。

打开build.prop文件(关键)。打开Root Explorer——system文件夹——点击变成“挂载为可读写”,英文为“Mount R/W”——长按build.prop,“以文本方式编辑”,英文为“open in text editor”。

修改build.prop文件(关键)。直接拉到最后一行,添加一行:qemu.hw.mainkeys=0——点右上角的,修改保存并退出,英文为“save and exit”。

6

重启手机,屏幕下方就会出现虚拟按键,跟触屏键功能一样。到此就可以使用了~

安卓手机怎么设置默认数字软键盘

可参考vivo手机的以下设置方式:

Funtouch OS 4.0及以上:i管家--应用管理--权限管理--最底部的默认应用设置。

Funtouch OS 3.0及3.2:设置--更多设置--应用程序--默认应用设置。

Funtouch OS 3.0以下:i管家--软件管理--默认软件设置。


网页标题:android自定义数字键盘,安卓手机键盘数字
网站网址:http://lszwz.com/article/dsdddje.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款