导航:首页 > 操作系统 > android自定义键盘按键

android自定义键盘按键

发布时间:2022-09-20 17:59:59

㈠ 关于android 自定义键盘的问题

在activity中使用的时候,首先要屏蔽掉系统软键盘,然后在输入框获取焦点的时候弹出你的键盘就OK了,键盘你可以用button来实现,或者就用一张图片算坐标重写ontouch都行;点数字的时候你就把你点的那个数字settext到你的输入框里,delete的时候你就把你输入框的文字去掉一位就OK了。如果让我做的话思路大概是这样的!

㈡ Android开发之如何自定义数字键盘详解

我曾经在项目中做过一个数字键盘,使用的是12个按钮:0~9,删除,确认
隐藏自带的手机键盘或者禁止EditText调出自带键盘,点击数字按钮时在EditText的内容中添加对应的数字,并且自己处理删除和确认的逻辑。

㈢ 安卓模拟器上怎么设置键盘按键,鼠标移动画面打手机游戏

模拟器右边工具栏有一个 按键操控

点开 就可以设置键盘按键了

模拟器里面鼠标点击 就等于手机的点击键


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

1.自定义数字键盘
2.切换到随机数字键盘
3.自定义确定和删除等键(向外抛出接口)

使用方法:
1.在项目build.gradle文件中添加jitpack,添加jitpcak就够了。allprojects{undefinedrepositories{undefinedjcenter()maven{url'https://jitpack.io'}}}2.在mole的build.gradle文件添加依赖compile'com.github.Simon986793021:NumberKeyboard:v1.0Ɖ.在布局文件中添加布局android:id="@+id/keyboard_view"xmlns:android="http://schemas.android.com/apk/res/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@(){undefinedToast.makeText(MainActivity.this,"隐藏键盘",Toast.LENGTH_SHORT).show();}});只需要这些简单的代码就能够实现一个自己定义的键盘了。实现过程1.新建一个keyboard布局在看这个代码之前需要了解keyboard的属性:不清楚属性,怎么画页面,不懂的请移步这篇博客在res新建一个xml文件,然后在xml新建一个keyboard.xml里面代码如下xmlns:android="http://schemas.android.com/apk/res/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.*/{;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()>1&&key.codes.length<2){undefinedintlabelTextSize=0;try{undefinedfield=KeyboardView.class.getDeclaredField("mLabelTextSize");field.setAccessible(true);labelTextSize=(int)field.get(this);}catch(NoSuchFieldExceptione){undefinede.printStackTrace();}catch(IllegalAccessExceptione){undefinede.printStackTrace();}paint.setTextSize(labelTextSize);paint.setTypeface(Typeface.DEFAULT_BOLD);}else{undefinedintkeyTextSize=0;try{undefinedfield=KeyboardView.class.getDeclaredField("mLabelTextSize");field.setAccessible(true);keyTextSize=(int)field.get(this);}catch(NoSuchFieldExceptione){undefinede.printStackTrace();}catch(IllegalAccessExceptione){undefinede.printStackTrace();}paint.setTextSize(keyTextSize);paint.setTypeface(Typeface.DEFAULT);}paint.getTextBounds(key.label.toString(),0,key.label.toString().length(),bounds);canvas.drawText(key.label.toString(),key.x+(key.width/2),(key.y+key.height/2)+bounds.height()/2,paint);}elseif(key.icon!=null){undefinedkey.icon.setBounds(key.x+(key.width-key.icon.getIntrinsicWidth())/2,key.y+(key.height-key.icon.getIntrinsicHeight())/2,key.x+(key.width-key.icon.getIntrinsicWidth())/2+key.icon.getIntrinsicWidth(),key.y+(key.height-key.icon.getIntrinsicHeight())/2+key.icon.getIntrinsicHeight());key.icon.draw(canvas);}}}3.KeyBoard的对象的创建:packagecom.wind.keyboard;importandroid.app.Activity;importandroid.content.Context;importandroid.inputmethodservice.Keyboard;importandroid.inputmethodservice.KeyboardView;importandroid.os.Build;importandroid.text.Editable;importandroid.text.InputType;importandroid.util.Log;importandroid.view.View;importandroid.view.inputmethod.InputMethodManager;importandroid.widget.EditText;importjava.lang.reflect.Method;importjava.util.ArrayList;importjava.util.LinkedList;importjava.util.List;importjava.util.Random;/***Createdbyzhangcongon2017/8/28.*/publicclassOfoKeyboard{;privateKeyboardkeyboard;;privateEditTexteditText;privatebooleanisRandom=false;publicOfoKeyboard(Activityactivity){undefinedthis.activity=activity;keyboardView=(OfoKeyboardView)activity.findViewById(R.id.keyboard_view);}//点击事件触发publicvoidattachTo(EditTexteditText,booleanisRandom){undefined/*切换键盘需要重新newKeyboard对象,否则键盘不会改变,keyboardView放到构造函数里面,避免每次点击重新new对象,提高性能*/keyboard=newKeyboard(activity,R.xml.keyboard);this.isRandom=isRandom;Log.i(">>>>>","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.=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!=null&&editable.length()>0){undefinedif(start>0){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;;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);}(){undefinedListkeyList=keyboard.getKeys();//查找出0-9的数字键ListnewkeyList=newArrayList();for(inti=0;i

㈤ android自定义键盘 如何输入中文

不同的手机品牌型号的ndroid的自定义键盘略有不同
一般在键盘的最下一排都有一个中英文转换键,点击下变中文,不过有的是全键盘拼音输入中文,有的是9键拼音中文;
在键盘上面有一排图标,是有选择手写输入、全键盘输入、9键拼音输入等各种输入法的选择键。

㈥ android 怎么改键盘按键

首先,保证手机已经ROOT,并且安装了RE文件管理器,先用RE管理器打开system\usr\keylayout下的文件s3c-keypad.kl(以文本编辑方式打开),在目录中不同的数字对应不同的功能,看好原先对应的功能,在将数字按照喜欢的风格进行重新编写:
1.
116代表锁屏键
2.
102代表宝石键
3.
231代表拨号键
4.
217代表相机上面的键
5.
26代表挂机键
6.
115代表音量+
7.
114代表音量-
8.
158代表相机键
9.
改完立刻重启就OK了。

㈦ android自定义软键盘,如何屏蔽系统自带键盘

在需要的地方加上以下代码就行了

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
view是你的某个控件,放在onClickListener中就可以屏蔽单击时的键盘了

㈧ 如何自定义软键盘android

软键盘实现

通过android.inputmethodservice.Keyboard只需要在XML文件中定义键盘布局就可以了,XML代码:

resxmlstock.xml
<?xmlversion="1.0"encoding="utf-8"?>
<Keyboardxmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="20%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="@dimen/key_height"
>
<Row>
<Keyandroid:codes="49"android:keyLabel="1"
android:keyEdgeFlags="left"/>
<Keyandroid:codes="50"android:keyLabel="2"/>
<Keyandroid:codes="51"android:keyLabel="3"/>
<Keyandroid:codes="52"android:keyLabel="4"/>
<Keyandroid:codes="53"android:keyLabel="5"
android:keyEdgeFlags="right"/>
</Row>
<Row>
<Keyandroid:codes="54"android:keyLabel="6"
android:keyEdgeFlags="left"/>
<Keyandroid:codes="55"android:keyLabel="7"/>
<Keyandroid:codes="56"android:keyLabel="8"/>
<Keyandroid:codes="57"android:keyLabel="9"/>
<Keyandroid:codes="48"android:keyLabel="0"
android:keyEdgeFlags="right"/>
</Row>
<Row>
<Keyandroid:codes="97"android:keyLabel="a"
android:keyEdgeFlags="left"/>
<Keyandroid:codes="99"android:keyLabel="c"/>
<Keyandroid:codes="102"android:keyLabel="f"/>
<Keyandroid:codes="46"android:keyLabel="."/>
<Keyandroid:codes="-5"
android:keyIcon="@drawable/sym_keyboard_delete"
android:keyEdgeFlags="right"
android:isRepeatable="true"/>
</Row>
<Rowandroid:rowEdgeFlags="bottom">
<Keyandroid:codes="-3"android:keyWidth="20%p"
android:keyIcon="@drawable/sym_keyboard_done"
android:keyEdgeFlags="left"/>
<Keyandroid:codes="-2"android:keyLabel="123"android:keyWidth="20%p"/>
<Keyandroid:keyOutputText="600"android:keyLabel="600"
android:keyWidth="20%p"/>
<Keyandroid:keyOutputText="000"android:keyLabel="000"
android:keyWidth="20%p"/>
<Keyandroid:codes="10"android:keyWidth="20%p"
android:keyIcon="@drawable/sym_keyboard_return"
android:keyEdgeFlags="right"/>
</Row>
</Keyboard>

㈨ android的手机,键盘定义fn键,用作数字和字母切换,请问这个键值应该定义成多少

如果是自定义键盘里面的话,xml文件里面的简直可以是-3,如下内容:
<Key android:codes="-3" android:keyWidth="20%p"
android:keyIcon="@drawable/sym_keyboard_done"
android:keyEdgeFlags="left" />

阅读全文

与android自定义键盘按键相关的资料

热点内容
如何保证服务器优质 浏览:92
小微信aPP怎么一下找不到了 浏览:299
算法纂要学术价值 浏览:973
程序员你好是什么意思 浏览:799
倩女幽魂老服务器如何玩 浏览:559
电子钟单片机课程设计实验报告 浏览:997
看加密频道 浏览:379
程序员算不算流水线工人 浏览:632
三星电视我的app怎么卸载 浏览:44
简述vi编译器的基本操作 浏览:507
让程序员选小号 浏览:91
加强数字货币国际信息编译能力 浏览:584
购买的app会员怎么退安卓手机 浏览:891
程序员的种类及名称 浏览:293
美国程序员薪资 浏览:13
黑石通汇证券服务器什么时候到期 浏览:393
东方财富app里我的关注怎么看 浏览:749
bm3d单反级降噪算法 浏览:457
华为安卓机激活时间怎么查询 浏览:850
如何用优盘重装服务器系统 浏览:317