android软件简约记账app开发day03-自定义键盘的书写
我们在fragment界面使用了自定义的keybroad键盘,所以今天我们来书写自定义的键盘代码
新建util包,新建keyboardutils的java类,当然在之前我们已经在项目中导入了google的material的jar包了。
package com.open.tally.util;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.text.Editable;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import com.open.tally.R;
public class KeyBoardUtils {
private final Keyboard k1;//自定义键盘
private KeyboardView keyboardView;
private EditText editText;
public interface OnEnsureListener{
public static void onEnsure(){
}
}
OnEnsureListener onEnsureListener;
public void setOnEnsureListener(OnEnsureListener onEnsureListener) {
this.onEnsureListener = onEnsureListener;
}
public KeyBoardUtils(KeyboardView keyboardView, EditText editText) {
this.keyboardView = keyboardView;
this.editText = editText;
this.editText.setInputType(InputType.TYPE_NULL);//取消弹出系统键盘
k1 = new Keyboard(this.editText.getContext(), R.xml.key);
this.keyboardView.setKeyboard(k1);
this.keyboardView.setEnabled(true);
this.keyboardView.setPreviewEnabled(false);
this.keyboardView.setOnKeyboardActionListener(listener);
}
KeyboardView.OnKeyboardActionListener listener=new KeyboardView.OnKeyboardActionListener() {
