解雇键盘ACTION_DONE preSS的Android preferences对话框 [英] Dismiss android preferences dialog on Keyboard ACTION_DONE press
问题描述
我希望能够关闭编辑preference对话框(如下图所示 http://twitpic.com / 18ttdp )由pressing键盘上的完成按钮。
I would like to be able to close the editpreference dialog (as shown here http://twitpic.com/18ttdp) by pressing the 'Done' button on the keyboard.
目前,完成pressing刚刚驳回了键盘,但离开对话框。
Currently, pressing 'Done' just dismisses the keyboard but leaves the dialog.
在我的应用程序的其他部分我使用类似code以下拦截完成键preSS和我的活动执行动作:
In other parts of my application I use code similar to the following to intercept the 'Done' key press and execute actions in my activity:
text.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
//do stuff here
return true;
}
return false;
}
});
不过,我不确定如何做到实现我的preference活动或布局XML这个同样的效果。
However, I am unsure of how to do achieve this same effect in my preference activity or layout xml.
推荐答案
下面是我如何解决它:
final EditTextPreference namePref = (EditTextPreference) findPreference("name");
namePref.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_ACTION_DONE) {
namePref.onClick(null, DialogInterface.BUTTON_POSITIVE);
namePref.getDialog().dismiss();
return true;
}
return false;
}
});
但你可能要考虑继承的EditText preference代替,因为这的onClick调用是一个黑客,它的实现可能在未来改变。
But you may want to consider subclassing EditTextPreference instead, since this onClick call is a hack, and its implementation may change in the future.
这篇关于解雇键盘ACTION_DONE preSS的Android preferences对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!