public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private EditText etPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
etPassword = (EditText) findViewById(R.id.etPassword);
...
//密码错误时的业务
etPassword.setText("");//重置编辑框为空
//让输入框重新获取焦点
etPassword.setFocusable(true);
etPassword.setFocusableInTouchMode(true);
etPassword.requestFocus();
//通过调用输入管理器来自动弹出软键盘
InputMethodManager inputMethodManager = (InputMethodManager) etPassword.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(etPassword, 0);
...
}
}
EditText密码输入错误后重新获取焦点并自动弹出软键盘
最新推荐文章于 2020-07-08 09:00:53 发布