对于Android Studio的用户,可以选择添加:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
compile 'com.github.ppg408331701:DigitalKeyboard:v1.0.0'
配置参数 | 参数含义 |
---|---|
DK_text_color | 键盘中的所有文本的颜色 |
DK_line_color | 键盘中分割线和边框的颜色 |
在xml中使用
<com.ppg.digitalnumkeyboard.DigitalNumKeyboard
android:id="@+id/DigitalNumKeyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
</com.ppg.digitalnumkeyboard.DigitalNumKeyboard>
edit = (EditText) findViewById(R.id.edit);
digitalNumKeyboard = (DigitalNumKeyboard) findViewById(R.id.DigitalNumKeyboard);
digitalNumKeyboard.setOnImgBackListener(new DigitalNumKeyboard.OnImgBackListener() {
@Override
public void ImgBackClickListener() {
digitalNumKeyboard.setVisibility(View.GONE);
}
});
digitalNumKeyboard.setOnNumBtnClickListener(new DigitalNumKeyboard.OnNumBtnClickListener() {
@Override
public void NumBtnClickListener(BtnBean btnBean) {
if (btnBean.getBtn_type() == BtnBean.BTN_TYPE_NUM) {
edit.setText(edit.getText().toString() + btnBean.getBtn_text());
} else if (btnBean.getBtn_type() == BtnBean.BTN_TYPE_POINT) {
edit.setText(edit.getText().toString() + btnBean.getBtn_text());
} else if (btnBean.getBtn_type() == BtnBean.BTN_TYPE_DELETE && edit.getText().length() > 0) {
int index = edit.getText().length(); //获取Edittext光标所在位置
edit.getText().delete(index - 1, index);
}
edit.setSelection(edit.getText().length());
}
});