在edittext中显示用户ID的文本和数字键盘

问题描述 投票:4回答:1

我正在创建一个Android应用程序,我需要用户填写表单。在这种形式中,存在用户必须放置她/他的ID(例如护照)的字段,并且我想知道是否可以同时显示具有数字和文本的键盘。

提前致谢。

android android-edittext keyboard android-softkeyboard
1个回答
0
投票

如果要设置运行时键盘的类型,请使用以下示例:

EditText editText = (EditText) findViewById(R.id.its_your_EditText); 
editText.setInputType(EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); //TYPE_CLASS_TEXT is the default

如果要立即显示键盘,请使用此示例:

if (editText.requestFocus()) {
    InputMethodManager imm = (InputMethodManager)
    getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}
© www.soinside.com 2019 - 2024. All rights reserved.