导航:首页 > 操作系统 > androidkeyboardview

androidkeyboardview

发布时间:2022-06-15 07:20:46

android输入法 Keyboardview怎么获取下面的字母

添加了OnKeyboardActionListener后的OnKey、OnPress、OnRelease方法和这有关,
但是,比如我手一次性滑过q、w、e、r四个字母,我想让我的程序知道这四个字母都被划过了,
这个过程中OnPress可以获得“q”字母,而OnKey、OnRelease获得的是“r”这个字母,
而w、e没有地方可以得到

❷ android 键盘弹出后view向上移动

android:windowSoftInputMode="adjustPan"

❸ android 自定义View在弹出的软键盘之上,怎么做

我以前也遇到过这个问题啊,自定义Dialog继承自AlertDialog,没有办法弹出软键盘,后来只改了一个地方,用Dialog,软键盘就出来了。AlertDialog源码中本身有代码禁用了软键盘,因为AlertDialog本身是没有输入框的,android本意就是让我们自定义对话框的时候选择Dialog。 你这一句:final Dialog dialog = new AlertDialog.Builder(mContext).create(); 可以直接new Dialog(context)试一试看 你可以参考下我以前写的代码,很乱,几年写的=.= // 登录的提示框 private void showDL(){ final Dialog dig = new Dialog(this); dig.show(); Window window2 = dig.getWindow(); /* *这个方法无法弹出软键盘 *final AlertDialog dlg = new AlertDialog.Builder(this).create(); *dlg.show(); *Window window = dlg.getWindow(); */ // 自定义的dialog布局 window2.setContentView(R.layout.denglu_ttishikuang); final EditText edt_dl = (EditText) window2.findViewById(R.id.tsk_et_zh); final EditText edt_mm = (EditText) window2.findViewById(R.id.tsk_et_mm); Button btn_qx = (Button) window2.findViewById(R.id.tsk_but_qx); Button btn_dl = (Button) window2.findViewById(R.id.tsk_but_dl); TextView tv_zhuce = (TextView) window2.findViewById(R.id.tsk_tv_zhuce); btn_dl.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { // 登录操作 String zhanghao = edt_dl.getText().toString(); String password = edt_mm.getText().toString(); LoginDL(zhanghao, password); dig.cancel(); } }); btn_qx.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { // 取消操作 dig.cancel(); } }); tv_zhuce.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { // 注册操作 Intent intent = new Intent(MainActivity.this, ZhuCe.class); startActivity(intent); } }); } 希望能帮到你啊

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

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 KeyboardView的每个key的字体

在windows7操作系统,Android studio中使用按照如下步骤更改Android Studio的代码字体和颜色。
1、打开Android studio的设置界面,点击工具的扳手图标,

2、在设置搜索栏输入"Font",

3、更改一下设置,“Primary font”是更改字体样式,比如“楷体”,“Size”咱们可以更改字体的大小,“Line spacing”可以更改行间距,

4、更改之后单击“Apply”应用更改,然后单击“OK”,

❻ android软键盘属于哪个view

// 虚拟键盘隐藏 判断view是否为空
View view = getActivity().getWindow().peekDecorView();
if (view != null) {
//隐藏虚拟键盘
InputMethodManager inputmanger = (InputMethodManager) getActivity()
.getSystemService(MainActivity.INPUT_METHOD_SERVICE);
inputmanger.hideSoftInputFromWindow(view.getWindowToken(),
0);
}

❼ android输入法源码中没有定义popupwindow但是运行时点击key会出现popupwindow窗口。如何除去

KeyboardView keyboardView.setPreviewEnabled(false);

阅读全文

与androidkeyboardview相关的资料

热点内容
南诏pdf 浏览:745
windows如何代码bat启动服务器 浏览:454
软件太卡与服务器有什么关系 浏览:402
给心理治疗师pdf 浏览:218
robinhood加密交易条件 浏览:310
卫生间解压方法 浏览:450
u盘如何做加密文件放照片 浏览:329
文件夹自己加了exe 浏览:259
小猪cms直播系统源码 浏览:878
山东广电云服务器 浏览:354
javadate与mysqldate 浏览:244
javalong比较 浏览:12
加密大师看不见加密文件 浏览:307
想做一个业余程序员 浏览:793
python选出行 浏览:249
cat命令windows 浏览:910
python算术游戏 浏览:532
常微分方程第二版pdf 浏览:25
phpJava学多久 浏览:724
php博客毕业设计 浏览:796