android EditText 只能输入无法删除的解决方法

首先感谢: http://www.eoeandroid.com/thread-201857-1-1.html
public boolean dispatchKeyEvent(KeyEvent event) {
		//用户按下返回键
		if(event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
			if(event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
				Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
				startActivity(intent);
				overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
				RegisterActivity.this.finish();
			}
		}
		return true;
	}


在我的代码中,重写了一个方法去监听用户按键,最后返回的都是true,这就是只能输入无法删除的原因了,只需要把以上代码改成:

public boolean dispatchKeyEvent(KeyEvent event) {
		//用户按下返回键
		if(event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
			if(event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
				Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
				startActivity(intent);
				overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
				RegisterActivity.this.finish();
			}
			return false;
		}
		else {
			return super.dispatchKeyEvent(event);
		}
	}


你可能感兴趣的:(android)