我們大家都知道通過指定EditText的android:imeOptions屬性可以修改 輸入法enter鍵的顯示情況
例如:
android:imeOptions=”actionNext” 下一個配合android:nextFocusForward屬性一起使用
android:imeOptions=”actionSearch” 搜索
android:imeOptions=”actionDone” enter
android:imeOptions=”actionGo” 前往
如果我們單獨只設置android:imeOptions這個屬性的話,我們會悲劇的發現.輸入法的enter鍵一直都不會有變化
例如:
<EditText
android:id="@+id/etext_done"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
/>
而我們如果加上 android:inputType=””
然後隨便指定一種輸入類型.我們的imeOptions屬性也就起作用了
所以使用的時候記得設置
在activity或者fragment來監聽點擊了enter go 或者 search
edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
/*判斷是否是“GO”鍵*/
if(actionId == EditorInfo.IME_ACTION_GO){
/*隱藏軟鍵盤*/
InputMethodManager imm = (InputMethodManager) v
.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) {
imm.hideSoftInputFromWindow(
v.getApplicationWindowToken(), 0);
}
edittext.setText("success");
webview.loadUrl(URL);
return true;
}
return false;
}
});
文章出處
http://blog.csdn.net/u010399316/article/details/50569506