導航:首頁 > 操作系統 > 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 瀏覽:223
coloros備份後的文件夾 瀏覽:124
linux源碼pdf 瀏覽:789
什麼app在微信小程序里看電視電影 瀏覽:110
伺服器dns地址fec0 瀏覽:327
化州用什麼app交社保 瀏覽:494
linuxvi怎麼打開 瀏覽:245
程序員的電視劇完整版資源 瀏覽:921
運行時間軸的腳本命令是哪個 瀏覽:620
怎麼部署rtx伺服器 瀏覽:899
手機qq怎麼壓縮視頻文件 瀏覽:530
魔獸釣魚起鉤演算法 瀏覽:474
安卓手機怎麼知道蘋果手機在哪裡 瀏覽:830
華為雲伺服器企業試用 瀏覽:109
CRYPTO加密是什麼 瀏覽:49
平安三號壓縮包 瀏覽:330
潘石屹老師編程 瀏覽:833
pdf轉轉換成圖片 瀏覽:472
下載解壓球游戲 瀏覽:831
不用海綿不用棉花做解壓神器 瀏覽:846