Android Monitor soft keyboard determines search button and gives click events

Source: Internet
Author: User

在android的实践开发中,为了界面的美观,往往那些搜索框并没有带搜索按钮,而是调用了软键盘的搜索按钮,完成这次时间
    • 1
    • 2


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.