Aak*_*Aak 7 keyboard virtual android
我想覆盖ENTER虚拟键盘的键的行为,以便:
我一直在玩IME选项和标签,但只是没有得到我想要的.有人有什么建议吗?
在另一个论坛的帮助下,我找到了做到这一点的方法.
为了使它可重用,我创建了自己的超级对话框类,它包含2个OnKeyListener对象和一个抽象的提交方法:
public abstract class MyAbstractDialog extends Dialog {
/**
* OnKeyListener that puts the focus down when the ENTER key is pressed
*/
protected View.OnKeyListener onEnterFocusDown = new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
v.requestFocus(View.FOCUS_DOWN);
return true;
}
return false;
}
};
/**
* OnKeyListener that submits the page when the ENTER key is pressed
*/
protected View.OnKeyListener onEnterSubmitView = new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
submitView(v);
return true;
}
return false;
}
};
protected abstract void submitView(View v);
}
Run Code Online (Sandbox Code Playgroud)
现在在Dialog我可以使用这些对象在我的字段上设置:
// make the ENTER key on passwordField1 put the focus on the next field
passwordField1.setOnKeyListener(onEnterFocusDown);
// make the ENTER key on passwordField2 submit the page
passwordField2.setOnKeyListener(onEnterSubmitView);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5418 次 |
| 最近记录: |