3

我有一个标准的条目弹出对话框

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);

    builder.setTitle(title)
        .setMessage(message)
        .setPositiveButton(buttonPositif, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   // Send the positive button event back to the host activity
                   mListener.onDialogPositiveClick(EntryDialogFacade.this);
               }
           })
        .setNegativeButton(buttonNegatif, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   // Send the negative button event back to the host activity
                   mListener.onDialogNegativeClick(EntryDialogFacade.this);
               }
           });        

    editText = new EditText(activity);
    editText.setLines(1);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    builder.setView(editText);

    Dialog dialog = builder.create();        
    dialog.show();

我正在尝试在输入字段键盘上显示“完成”按钮(请参阅代码片段),但是,这种方式不起作用。

会有人经历过同样的事情吗?

干杯。

4

1 回答 1

4

你需要使用setSingleLine(true)而不是setLines(1)然后你需要一个EditorActionListener来抓住Done钥匙。

editText.setSingleLine(true);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setOnEditorActionListener(new OnEditorActionListener() {

    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        Toast.makeText(MainActivity.this, "Got IME Done", Toast.LENGTH_SHORT).show();
        return true;
    }
});
于 2012-11-19T22:45:00.963 回答