我有两个EditText txtPassword,txtMail基于单选按钮更改事件我只是隐藏并显示txtPassword字段
我只想用porgramatic更改imeoptions,为此我编写了以下代码
txtPassword.setImeOptions(EditorInfo.IME_ACTION_DONE);
txtEmail.setImeOptions(EditorInfo.IME_ACTION_NEXT);
但这不管用。当我观察软键盘时,这会显示txtmail中的done操作(只是因为在更改收音机之前,只有txtmail可见,所以会显示automatic done)
但在手动聚焦于密码字段之后,如果我观察到带有电子邮件字段的软键盘,它会自动使用下一个imeoptions更改它。我只想如果一个txtmail是可见的比它做了imeoptions和如果txtpassword,txtmail都是可见的比txtmail有imeoptions下一步和在txtpassword中它有显示完成imeoptions。提前谢谢。
编辑:
radiologin.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group,int checkedId) {
// checkedId is the RadioButton selected
if (checkedId == R.id.radioWithoutPassword) {
txtPassword.setVisibility(View.GONE);
txtEmail.setBackgroundDrawable(getResources().getDrawable(R.drawable.both_corner));
txtEmail.setImeOptions(EditorInfo.IME_ACTION_DONE);
}
else
{
txtEmail.setImeOptions(EditorInfo.IME_ACTION_NEXT);
txtPassword.setImeOptions(EditorInfo.IME_ACTION_DONE);
txtPassword.setVisibility(View.VISIBLE);
txtEmail.setBackgroundDrawable(getResources().getDrawable(R.drawable.top_corner));
}
}
});
最佳答案
试试这个,
final EditText passwordEditText = new EditText(this);
final EditText emailEditText = new EditText(this);
RadioButton button = new RadioButton(this);
button.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
passwordEditText.setVisibility(View.INVISIBLE);
emailEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
}else{
emailEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
}
}
});
并始终设置
passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
。关于android - Android imeOptions以编程方式更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17501426/