当视图加载时,我想强制SIP打开并显示带有数字的键盘。另外,我希望editText视图接受来自SIP
的字母和数字输入。XML
<EditText android:id="@+id/search_bus_by_num_keyword"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:lines="1" android:layout_weight="1"
android:inputType="numberDecimal"
/>
Code
editTextSearchKeyword = (EditText) context.findViewById(R.id.search_bus_by_num_keyword);
editTextSearchKeyword.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
context.hideSIP(editTextSearchKeyword);
searchRoute();
return true;
}
return false;
}
});
editTextSearchKeyword.setText(searchKeyword);
editTextSearchKeyword.requestFocus();
InputMethodManager mgr = (InputMethodManager) context.getSystemService(context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(editTextSearchKeyword, InputMethodManager.SHOW_FORCED);
当视图加载时:http://pwong.name/sip_01.png
当SIP由"号码"改为"字母"时:http://pwong.name/sip_02.png,我不能在editText视图中输入字母。
是否可以输入数字和字母的editText,如果我设置android:inputType="numberDecimal"到它?是否有可能在运行时改变android:inputType ?
参见如何在代码中更改InputType的问题。有关EditText输入类型,请参见此链接。根据您的要求"我想强制SIP打开并显示带有数字的键盘"。此外,我想要一个editText视图接受来自SIP的字母和数字输入-我不明白。我不认为你可以为一个EditText有多个输入模式
试试这个代码
android:inputType="textVisiblePassword"