android 改變輸入法enter鍵文字 爲搜索 下一個 以及前往

我們大家都知道通過指定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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章