Android Create custom SearchView Search action

前端 未结 1 1395
春和景丽
春和景丽 2020-12-05 01:14

In my application I am using the Action Bar with a custom SearchView in it. I want to use some custom code when the user hits the enter button in the search field. But I can

相关标签:
1条回答
  • 2020-12-05 01:56

    Get your search view and add an OnQueryTextListener

    final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            // Do something
            return true;
        }
    
        @Override
        public boolean onQueryTextSubmit(String query) {
            // Do something
            return true;
        }
    };
    
    searchView.setOnQueryTextListener(queryTextListener);
    

    By the way my menu layout is as follows;

    <item android:id="@+id/menu_search"
        android:showAsAction="ifRoom"
        android:actionViewClass="android.widget.SearchView" />
    
    0 讨论(0)
提交回复
热议问题