简体   繁体   English

将软键盘上的下一个按钮更改为完成按钮不起作用

[英]Changing next button to done button on soft keyboard doesn't work

When the user clicks an icon in the action bar, an AlertDialog opens to save the data. 当用户单击操作栏中的图标时,将打开AlertDialog来保存数据。 To enter the name of the file, a soft keyboard appears. 要输入文件名,将出现一个软键盘。 In this keyboard I want to change the ENTER button with a DONE. 在此键盘上,我想用“完成”更改“输入”按钮。 I applied ".setImeOptions(EditorInfo.IME_ACTION_DONE);" 我套用了“ .setImeOptions(EditorInfo.IME_ACTION_DONE);” but it doesn't work. 但这不起作用。 This is my code for the AlertDialog: 这是我的AlertDialog代码:

public void openSaveBox (){ 公共无效的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();
}

What am I doing wrong? 我究竟做错了什么?

Set the InputType for the Edit text input before ImeOptions ie InputType之前设置InputType输入的ImeOptions

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM