android edittext 把软键盘确认键改为搜索键
生活随笔
收集整理的這篇文章主要介紹了
android edittext 把软键盘确认键改为搜索键
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
EditText搜索時沒有搜索按鈕,而是調(diào)用軟件盤上的按鈕,這時便需要改變軟鍵盤的確定鍵為“搜索”,并監(jiān)聽該鍵的按鈕。
在xml文件中添加:
android:imeOptions="actionSearch"
android:singleLine="true"
其中android:singleLine="true"表示保證點(diǎn)擊不會換行
android:imeOptions="actionSearch"表示改為搜索鍵
并且在代碼中設(shè)置監(jiān)聽
mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {@Overridepublic boolean onEditorAction(TextView v, int actionId, KeyEvent event) {search();//搜索方法//隱藏軟鍵盤 InputMethodManager imm = (InputMethodManager)context.getSystemService("input_method");imm.toggleSoftInput(0, 2);? return true; }});
總結(jié)
以上是生活随笔為你收集整理的android edittext 把软键盘确认键改为搜索键的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: microsoftstore连不上网_修
- 下一篇: 海报设计如何做好文案超多的海报