Android 自定义软键盘实现
生活随笔
收集整理的這篇文章主要介紹了
Android 自定义软键盘实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
module鏈接:https://download.csdn.net/download/meixi_android/10652565
compile project(':edlibrary') , ':edlibrary' <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/root_view"android:orientation="vertical"><ScrollViewandroid:id="@+id/sv_main"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"><LinearLayoutandroid:id="@+id/all_ed"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><EditTextandroid:id="@+id/normal_ed"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="普通鍵盤" /><EditTextandroid:id="@+id/special_ed"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="特殊鍵盤"android:inputType="numberPassword"/></LinearLayout></ScrollView> </LinearLayout>?
private LinearLayout rootView; private ScrollView scrollView;private EditText specialEd; private KeyboardUtil keyboardUtil; @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);rootView = (LinearLayout) findViewById(R.id.root_view);scrollView = (ScrollView) findViewById(R.id.sv_main);specialEd = (EditText) findViewById(R.id.special_ed);initMoveKeyBoard();}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 ) {if(keyboardUtil.isShow){keyboardUtil.hideSystemKeyBoard();keyboardUtil.hideAllKeyBoard();keyboardUtil.hideKeyboardLayout();}else {return super.onKeyDown(keyCode, event);}return false;} elsereturn super.onKeyDown(keyCode, event);}private void initMoveKeyBoard() {keyboardUtil = new KeyboardUtil(this, rootView, scrollView); // keyboardUtil.setOtherEdittext(normalEd);// monitor the KeyBarod statekeyboardUtil.setKeyBoardStateChangeListener(new KeyBoardStateListener());// monitor the finish or next KeykeyboardUtil.setInputOverListener(new inputOverListener());specialEd.setOnTouchListener(new KeyboardTouchListener(keyboardUtil, KeyboardUtil.INPUTTYPE_NUM, -1));}class KeyBoardStateListener implements KeyboardUtil.KeyBoardStateChangeListener {@Overridepublic void KeyBoardStateChange(int state, EditText editText) { // System.out.println("state" + state); // System.out.println("editText" + editText.getText().toString());}}class inputOverListener implements KeyboardUtil.InputFinishListener {@Overridepublic void inputHasOver(int onclickType, EditText editText) { // System.out.println("onclickType" + onclickType); // System.out.println("editText" + editText.getText().toString());}}總結
以上是生活随笔為你收集整理的Android 自定义软键盘实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么使用Docker搭建PHP开发环境呢
- 下一篇: Android获取屏幕尺寸,屏幕适配