我正在创建登录屏幕并且编辑文本键盘出现问题。应用程序加载,然后您将在第一个编辑文本中输入您的名字,但有时它会加载键盘。所以你再次按它并且它不会显示。要让它再次显示的唯一方法是单击名为etPassword
的第二个编辑文本。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Pushbots.sharedInstance().init(this);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_login);
etUsername = (EditText) findViewById(R.id.etUsername);
etPassword = (EditText) findViewById(R.id.etPassword);
tvRegister = (TextView) findViewById(R.id.tvRegister);
tvAboutus = (TextView) findViewById(R.id.tvAboutus);
tvContact = (TextView) findViewById(R.id.tvContact);
tvDonate = (TextView) findViewById(R.id.tvDonate);
bLogin = (Button) findViewById(R.id.bLogin);
cbRememberme = (CheckBox) findViewById(R.id.cbRememberme);
etUsername.setOnClickListener(this);
etPassword.setOnClickListener(this);
tvRegister.setOnClickListener(this);
tvAboutus.setOnClickListener(this);
tvContact.setOnClickListener(this);
tvDonate.setOnClickListener(this);
bLogin.setOnClickListener(this);
etUsername.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
// hide virtual keyboard
InputMethodManager imm =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
return true;
}
return false;
}
});
etPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
// hide virtual keyboard
InputMethodManager imm2 =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm2.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
return true;
}
return false;
}
});
}
答案 0 :(得分:0)
您正在使用
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
尝试删除这些调用并添加此
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
在onCreate()
中。这将强制键盘自动出现。