2012-11-26 104 views
28

我尝试使用input.setImeOptions(EditorInfo.IME_ACTION_DONE)设置软键盘上的“完成”按钮;setImeOptions:为什么“完成”按钮不显示在软键盘上?

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

有什么建议吗?

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();     
} 

回答

52

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

尝试增加

input.setSingleLine(); 

而且你会看到,按下键盘的操作键将实际执行一个“完成”行动(即关闭键盘)

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

+1

如果什么你想要一个带有换行但没有显式换行符的多行文本框? –

+0

在Layout XML中使用android:imeOptions =“actionUnspecified”.. – AnkitRox