【问题标题】:Changing next button to done button on soft keyboard doesn't work将软键盘上的下一步按钮更改为完成按钮不起作用
【发布时间】:2016-02-22 07:07:45
【问题描述】:

当用户单击操作栏中的图标时,会打开一个 AlertDialog 以保存数据。 要输入文件名,会出现一个软键盘。在这个键盘上,我想用 DONE 更改 ENTER 按钮。我应用了“.setImeOptions(EditorInfo.IME_ACTION_DONE);”但它不起作用。这是我的 AlertDialog 代码:

public void openSaveBox(){

    final AlertDialog ad = new AlertDialog.Builder(this).create();
    ad.setTitle("OCRA score bewaren");
    ad.setMessage("Geef een bestandsnaam in:");
    final EditText input = new EditText(this);        
    ad.setView(input);

    ad.setButton2("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String file = input.getText().toString();
            bewaren(file);
            ad.dismiss();
        }
    });
    ad.setButton("Annuleren", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            ad.dismiss();
        }
    });

    ad.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    input.setImeOptions(EditorInfo.IME_ACTION_DONE);

    ad.show();
}

我做错了什么?

【问题讨论】:

    标签: android


    【解决方案1】:

    ImeOptions之前为编辑文本输入设置InputType,即

      input.setInputType(EditorInfo.TYPE_CLASS_TEXT);
      input.setImeOptions(EditorInfo.IME_ACTION_DONE);
    

    【讨论】:

    • @Michael_D 如果有效,您应该接受答案
    猜你喜欢
    • 2011-02-03
    • 2011-09-13
    • 2012-09-11
    • 2020-07-05
    • 2012-11-13
    • 2023-04-04
    • 2012-07-18
    • 1970-01-01
    • 2015-09-17
    相关资源
    最近更新 更多