在android的实践开发中,为了界面的美观,往往那些搜索框并没有带搜索按钮,而是调用了软键盘的搜索按钮,完成这次时间
All right! Directly on the code!
<edittext android:id="@+id/my_chat_seach "Android:layout_width=" fill_parent " Android:layout_height= "23DP" Android:layout_centervertical= "True" Android:layout_marginright= "6dip" android:layout_torightof= " @id/my_seach_item_1_button" Android:background= " @color/white" Android:gravity= " Center_vertical "Android:hint=" @string/search "Android: Imeoptions= "Actionsearch" Android:singleline= "true" Android: Textcolor= "#8e8787" Android:textsize= "13sp"/>
One of the most important attributes in an XML configuration file is: android:imeoptions= "Actionsearch", so that when a soft keyboard is called, the ENTER key will display the search word.
At the same time in the Androidmainfest.xml file in this activity write android:windowsoftinputmode= "Adjustpan", you can prevent the soft keyboard will be the original interface to squeeze up the problem.
So how does it work in this activity?
seachEditText = (EditText) findViewById(R.id.my_chat_seach);watchSearch();
And then
/** * @ Method Description: Monitor the soft keyboard Search button * @ Method Name: Watchsearch * @ return value: void */PublicvoidWatchsearch () {Seachedittext.setoneditoractionlistener (new Oneditoractionlistener () { @Override public boolean oneditoraction (TextView V, int ActionId, KeyEvent event) {if (ActionId = = Editorinfo.ime_action_ SEARCH) {//first hides the keyboard ((Inputmethodmanager) Seachedittext.getcontext (). Getsystemservice ( Context.input_method_service). Hidesoftinputfromwindow (Chatfriendsgroudseach. this. Getcurrentfocus (). Getwindowtoken (), inputmethodmanager.hide_not_always); //search, do your own action ... seachlist (ViewIndex); //here's what I'm going to do! return true;} return false;}); }
Good! Complete!
Android Monitor soft keyboard determines search button and gives click events