導航:首頁 > 操作系統 > 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自定義鍵盤按鍵相關的資料

熱點內容
怎麼使用access的命令按鈕 瀏覽:897
有點錢app在哪裡下載 瀏覽:832
博途v15解壓後無法安裝 瀏覽:203
什麼是根伺服器主機 瀏覽:436
安卓手游怎麼申請退款 瀏覽:553
安卓系統如何分享網頁 瀏覽:278
ad如何編譯pcb工程 瀏覽:412
除了滴滴app哪裡還能用滴滴 瀏覽:399
截圖怎麼保存文件夾然後壓縮 瀏覽:8
幻影伺服器怎麼樣 瀏覽:27
具體哪些廣東公司招程序員 瀏覽:870
嵌入式編譯器教程 瀏覽:306
ssl數據加密傳輸 瀏覽:86
51單片機定時器方式2 瀏覽:331
命令行查看開機時間 瀏覽:813
python微博復雜網路分析 瀏覽:550
rf3148編程器 瀏覽:505
浙江標准網路伺服器機櫃雲主機 瀏覽:588
設置網路的伺服器地址 瀏覽:600
java圖形界面設計 瀏覽:751