我正在使用的代码是使用Toolbar和膨胀a menu。这是代码private Toolbar mToolbar;mToolbar.inflateMenu(R.menu.chat_screen_menu);setupMenu ();private void setupMenu () { mMenu = mToolbar.getMenu(); if (mMenu != null) { if (mChatPager != null && mChatPager.getCurrentItem() > 0) { mMenu.setGroupVisible(R.id.menu_group_chats, true); mMenu.setGroupVisible(R.id.menu_group_contacts, false); } else { mMenu.setGroupVisible(R.id.menu_group_chats, false); mMenu.setGroupVisible(R.id.menu_group_contacts, true); mMenu.setGroupVisible(R.id.menu_group_otr_verified,false); mMenu.setGroupVisible(R.id.menu_group_otr_unverified,false); mMenu.setGroupVisible(R.id.menu_group_otr_off,false); } } mToolbar.setOnMenuItemClickListener(new OnMenuItemClickListener () { .......... }}但现在,他们需要一个Search按钮tool_bar。我设法说出来了,我在这里按照指南 当我尝试写一些东西进行搜索时,我已经测试listener过的东西来测试从未显示过的东西。表示listener不起作用@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.chat_screen_menu, menu); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_menu_search)); final Toast toast = new Toast(mApp); if (mSearchView != null ) { mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); mSearchView.setIconifiedByDefault(false); SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { public boolean onQueryTextChange(String newText) { mSearchString = newText; //doFilterAsync(mSearchString); toast.makeText(getApplicationContext(), "Test1", Toast.LENGTH_LONG).show(); return true; }
3 回答
- 3 回答
- 0 关注
- 574 浏览
添加回答
举报
0/150
提交
取消