KeyboardInputDemo
這是一個(gè)仿支付寶自定義軟鍵盤的demo,分別為身份證號(hào)碼、支付金額、支付密碼輸入定制的軟鍵盤,以及EditText文本輸入框與密碼輸入框的定制。
先上效果圖:
image.png

圖片發(fā)自簡書App

圖片發(fā)自簡書App

圖片發(fā)自簡書App
一 身份證鍵盤
1 身份證鍵盤在MainActivity頁面,使用時(shí)再布局中添加配置
<com.example.weioule.inputkeyboarddemo.view.CEditText
android:id="@+id/indentity_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:clear="true"
app:hit="請(qǐng)輸入身份證號(hào)"
app:input_typed="email"
app:left_text="身份證號(hào)"
app:length="18"
app:show_bottom_split="false"
app:show_custom_keyboard="true"
tools:layout_height="60dp" />
要使用自定義的鍵盤記得配置:app:show_custom_keyboard="true"
2 在Activity中創(chuàng)建 CumKeyboardContainer:
mCustomKeyboardView = new CumKeyboardContainer(this, getInputType());
mCustomKeyboardView.attachKeyBoardView();
3 并為輸入框CEditText配置
mIndentityCard = findViewById(R.id.indentity_card);
mIndentityCard.setCustomKeyboardView(mCustomKeyboardView);
4 在onBackPressed中配置回退鍵盤,若鍵盤顯示則先隱藏
if (mCustomKeyboardView != null && mCustomKeyboardView.getVisibility() == View.VISIBLE) {
mCustomKeyboardView.setCmbVisibility(View.GONE);
}
二 數(shù)字鍵盤
數(shù)字鍵盤在SecondActivity頁面,使用方法同上,只是在第二步中修改類型為金額輸入:
mCustomKeyboardView = new CumKeyboardContainer(this, CumKeyboardContainer.AMOUT_TYPE);
三 支付密碼對(duì)話框
1 創(chuàng)建輸入框和回調(diào)方法
inputPayPwdDialog = new InputPayPwdDialog(this);
inputPayPwdDialog.setInputPasswordListener(new InputPayPwdDialog.PasswordListener() {
@Override
public void onSubmitPwd(String password) {
Toast.makeText(SecondActivity.this, "成功支付" + mIndentityCard.getText() + "元", Toast.LENGTH_SHORT).show();
}
});
2 在顯示的時(shí)候調(diào)用
inputPayPwdDialog.show();
3 獲取密碼
inputPayPwdDialog.getPassword();
項(xiàng)目地址:https://github.com/weioule/KeyboardInputDemo