<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLines="1"/>
android:focusable="true" android:focusableInTouchMode="true"
这两个属性添加是为了屏蔽输入法自动弹出问题,不过在此之上还需要在AndroidManifest.xml中配置
android:windowSoftInputMode="stateHidden"
输入法按键设置:
android:imeOptions="actionNext" 下一个配合android:nextFocusForward属性一起使用
android:imeOptions="actionSearch" 搜索
android:imeOptions="actionDone" enter
android:imeOptions="actionGo" 前往
如果我们单独只设置android:imeOptions这个属性的话,我们会悲剧的发现.输入法的enter键一直都不会有变化,而我们如果加上 android:inputType="",属性随意
edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
/*判断是否是“GO”键*/
if(actionId == EditorInfo.IME_ACTION_GO){
/*隐藏软键盘*/
InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
//添加自己的方法
return true;
}
return false;
}
});