【问题标题】:setImeOptions: why the "Done" button does not show on the soft keyboard?setImeOptions:为什么软键盘上不显示“完成”按钮?
【发布时间】:2012-11-13 18:00:29
【问题描述】:

我尝试使用 input.setImeOptions(EditorInfo.IME_ACTION_DONE) 设置软键盘上的“完成”按钮;

但“完成”按钮根本不显示在软键盘上。

有什么建议吗?

public void modif(int position) {
    AlertDialog.Builder alert = new  AlertDialog.Builder(MainActivity.this);
    alert.setTitle("Modifica");
    EditText input = new EditText(MainActivity.this);
    input.setImeOptions(EditorInfo.IME_ACTION_DONE);
    alert.setView(input);
    final Editable value = input.getText();
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {  
        public void onClick(DialogInterface dialog, int whichButton) {
            Toast.makeText(getApplicationContext(), value,   Toast.LENGTH_LONG).show();
        }
    });

    alert.setNegativeButton("Cancel", new     DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
        // Canceled.
        }
    });
    alert.show();                   
}

【问题讨论】:

    标签: android android-softkeyboard ime


    【解决方案1】:

    这可能是因为您的输入字段不是单行的。

    尝试添加

    input.setSingleLine();
    

    您会看到按下键盘的操作键实际上会执行“完成”操作(即关闭键盘)

    http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_DONE

    【讨论】:

    • 如果你想要一个带换行但没有明确换行符的多行文本框怎么办?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-19
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 2016-02-22
    • 2011-03-22
    相关资源
    最近更新 更多