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">
<ScrollView
android:id="@+id/sv_main"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="@+id/all_ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/normal_ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="普通键盘" />
<EditText
android: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;
@Override
protected 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();
}
@Override
public 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;
} else
return super.onKeyDown(keyCode, event);
}
private void initMoveKeyBoard() {
keyboardUtil = new KeyboardUtil(this, rootView, scrollView);
// keyboardUtil.setOtherEdittext(normalEd);
// monitor the KeyBarod state
keyboardUtil.setKeyBoardStateChangeListener(new KeyBoardStateListener());
// monitor the finish or next Key
keyboardUtil.setInputOverListener(new inputOverListener());
specialEd.setOnTouchListener(new KeyboardTouchListener(keyboardUtil, KeyboardUtil.INPUTTYPE_NUM, -1));
}
class KeyBoardStateListener implements KeyboardUtil.KeyBoardStateChangeListener {
@Override
public void KeyBoardStateChange(int state, EditText editText) {
// System.out.println("state" + state);
// System.out.println("editText" + editText.getText().toString());
}
}
class inputOverListener implements KeyboardUtil.InputFinishListener {
@Override
public void inputHasOver(int onclickType, EditText editText) {
// System.out.println("onclickType" + onclickType);
// System.out.println("editText" + editText.getText().toString());
}
}