输入框回车发送样式
<EditText
android:imeOptions="actionSend"
android:singleLine="true"/>
回车后监听
editLocation.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
}
});
隐藏软键盘
((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(getActivity().getCurrentFocus()
.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
return false;
输入框拿到焦点后隐藏软键盘
editNum.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
disableShowInput();
// closeInputMethod();
}
});
public void disableShowInput() {
if (android.os.Build.VERSION.SDK_INT <= 10) {
editNum.setInputType(InputType.TYPE_NULL);
} else {
Class<EditText> cls = EditText.class;
try {
method = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
method.setAccessible(true);
method.invoke(editNum, false);
} catch (Exception e) {//TODO: handle exception
}
try {
method = cls.getMethod("setSoftInputShownOnFocus", boolean.class);
method.setAccessible(true);
method.invoke(editNum, false);
} catch (Exception e) {//TODO: handle exception
}
}
}