EditText 软键盘
- package brother.eighteen.demoedittext;
- import android.content.Context;
- import android.text.InputType;
- import android.util.AttributeSet;
- import android.view.MotionEvent;
- import android.view.inputmethod.InputMethodManager;
- import android.widget.EditText;
- /**
- * @author zhangya
- */
- public class DigitEditText extends EditText {
- public DigitEditText(Context context,AttributeSet attrs) {
- super(context,attrs);
- setInputType(getInputType()|InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- boolean ret = super.onTouchEvent(event);
- final InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- if(imm != null && imm.isActive(this)){
- imm.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
- }
- return ret;
- }
- }
时间: 2024-11-08 01:26:43