2014-04-23 215 views

回答

1

你有两种选择。

使用XML:

<EditText 
      android:id="@+id/editText1" 
      android:inputType="text" 
      android:imeOptions="actionDone"/> 

与代码。

edittext.setOnEditorActionListener(new OnEditorActionListener() { 
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
       if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { 
        InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
        in.hideSoftInputFromWindow(edittext.getApplicationWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS); 
       } 
       return false; 
      } 
     }); 
+0

XML代码有效,但Java代码无效。仍然想知道为什么不。 – MatusMak