Java Code Examples for android.view.MenuItem#getActionView()
The following examples show how to use
android.view.MenuItem#getActionView() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From TutosAndroidFrance with MIT License | 6 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem search = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) search.getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { EventBus.getDefault().post(new SearchEvent(query)); return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); return super.onCreateOptionsMenu(menu); }
Example 2
Source File: ConditionOrderActivity.java From shinny-futures-android with GNU General Public License v3.0 | 6 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem menuItem = menu.findItem(R.id.right_navigation); FrameLayout rootView = (FrameLayout) menuItem.getActionView(); ImageView view = rootView.findViewById(R.id.view_menu); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(ConditionOrderActivity.this, ManagerConditionOrderActivity.class); ConditionOrderActivity.this.startActivity(intent); } }); mBadgeView = new QBadgeView(sContext).bindTarget(view) .setBadgeNumber(-1) .setBadgeBackgroundColor(sContext.getResources().getColor(R.color.launch)) .setBadgeGravity( Gravity.END | Gravity.TOP) .setBadgePadding(4, true) .setGravityOffset(8, 8, true) .setBadgeTextColor(sContext.getResources().getColor(R.color.white)); refreshCO(); return true; }
Example 3
Source File: ChapterDrawerFragment.java From HaoReader with GNU General Public License v3.0 | 6 votes |
private void inflateMenu() { toolbar.inflateMenu(R.menu.menu_search_view); MenuItem search = toolbar.getMenu().findItem(R.id.action_search); searchView = (SearchView) search.getActionView(); AppCompat.useCustomIconForSearchView(searchView, getResources().getString(R.string.search)); searchView.setMaxWidth(getResources().getDisplayMetrics().widthPixels); searchView.onActionViewCollapsed(); searchView.setOnCloseListener(() -> { tabLayout.setVisibility(VISIBLE); return false; }); searchView.setOnSearchClickListener(view -> tabLayout.setVisibility(GONE)); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { int tab = tabLayout.getSelectedTabPosition(); fragments[tab].getFilter().filter(newText); return false; } }); }
Example 4
Source File: ActivityMain.java From uPods-android with Apache License 2.0 | 6 votes |
private void init() { UpodsApplication.initAllResources(); vOverlay = findViewById(R.id.vOverlay); //Toolbar toolbar.inflateMenu(R.menu.menu_activity_main); toolbar.setOnMenuItemClickListener(this); toolbar.setTitleTextColor(getResources().getColor(R.color.white)); //Social callbackManager = CallbackManager.Factory.create(); MenuItem searchMenuItem = toolbar.getMenu().findItem(R.id.action_search); SearchView searchView = (SearchView) searchMenuItem.getActionView(); UIHelper.setSearchViewStyle(searchView); UIHelper.changeSearchViewTextColor(searchView, Color.WHITE); slidingMenu = new SlidingMenu(this, toolbar); }
Example 5
Source File: GamesFragment.java From UpdogFarmer with GNU General Public License v3.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_games, menu); final MenuItem searchItem = menu.findItem(R.id.search); searchView = (SearchView) searchItem.getActionView(); searchView.setOnQueryTextListener(this); super.onCreateOptionsMenu(menu, inflater); }
Example 6
Source File: MainActivity.java From NintendoSwitchEShopHelper with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.search_view, menu); MenuItem searchItem = menu.findItem(R.id.menu_item_search); final SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { QueryPreferences.setStoredQuery(mContext, query); updateItems(); searchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { QueryPreferences.setStoredQuery(mContext, newText.equals("") ? null : newText); updateItems(); return true; } }); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { QueryPreferences.setStoredQuery(mContext, null); updateItems(); searchView.onActionViewCollapsed(); return true; } }); return super.onCreateOptionsMenu(menu); }
Example 7
Source File: MenuBadgeUtils.java From AccountBook with GNU General Public License v3.0 | 5 votes |
/** * 更新消息数量,当 0 时隐藏. * @param act 菜单对应 Activity * @param menu 菜单 item * @param resId 菜单图片 * @param count 消息数量 */ public static void update(final Activity act, final MenuItem menu, int resId, int count){ if(menu == null) return; View badge = menu.getActionView(); if(badge == null){ menu.setActionView(R.layout.menu_action_item_badge); badge = menu.getActionView(); } ImageView imgBadge = (ImageView) badge.findViewById(R.id.menu_badge_icon); TextView txtBadge = (TextView) badge.findViewById(R.id.menu_badge); if(resId != -1){ imgBadge.setImageResource(resId); } if(count > 0){ txtBadge.setVisibility(View.VISIBLE); if(count < 10){ txtBadge.setTextSize(12f); txtBadge.setText(String.valueOf(count)); }else{ txtBadge.setTextSize(10f); txtBadge.setText("9+"); } }else{ txtBadge.setVisibility(View.GONE); } badge.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { act.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, menu); } }); }
Example 8
Source File: DownloadMapActivity.java From PocketMaps with MIT License | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_maps, menu); MenuItem searchItem = menu.findItem(R.id.menu_search_filter); SearchView searchView = (SearchView) searchItem.getActionView(); searchView.setQueryHint(getResources().getString(R.string.search_hint)); searchView.setOnQueryTextListener(this); searchView.setOnSearchClickListener(createHideMenuListener(menu)); searchView.setOnCloseListener(createShowMenuListener(menu)); return true; }
Example 9
Source File: AddTokensActivity.java From SSForms with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { menu.clear(); getMenuInflater().inflate(R.menu.tokens_picker_menu_main, menu); //super.onCreateOptionsMenu(menu, getMenuInflater()); MenuItem myActionMenuItem = menu.findItem(R.id.action_search); final SearchView searchView = (SearchView) myActionMenuItem.getActionView(); EditText searchEditText = searchView.findViewById(R.id.search_src_text); searchEditText.setTextColor(getResources().getColor(R.color.whiteColor)); searchEditText.setHintTextColor(getResources().getColor(R.color.whiteColor)); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { simpleSearchAdapter.filter(""); } else { simpleSearchAdapter.filter(newText); } return true; } }); return true; }
Example 10
Source File: BookShelfSearchView.java From HaoReader with GNU General Public License v3.0 | 5 votes |
private void initView(Context context) { LayoutInflater.from(context).inflate(R.layout.view_search_bookshelf, this, true); ButterKnife.bind(this); AppCompat.setToolbarNavIconTint(toolbar, getResources().getColor(R.color.colorBarText)); toolbar.inflateMenu(R.menu.menu_search_view); MenuItem search = toolbar.getMenu().findItem(R.id.action_search); searchView = (SearchView) search.getActionView(); AppCompat.useCustomIconForSearchView(searchView, getResources().getString(R.string.searchShelfBook)); searchAutoComplete = searchView.findViewById(R.id.search_src_text); searchView.setMaxWidth(getResources().getDisplayMetrics().widthPixels); searchView.onActionViewExpanded(); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { queryBooks(newText); return false; } }); rvList.setLayoutManager(new LinearLayoutManager(context)); adapter = new BookShelfListAdapter(context, -1, 1); rvList.setAdapter(adapter); toolbar.setNavigationOnClickListener(v -> { ViewParent parent = BookShelfSearchView.this.getParent(); if (parent instanceof DrawerLayout) { ((DrawerLayout) parent).closeDrawers(); } }); }
Example 11
Source File: MainActivity.java From android_gisapp with GNU General Public License v3.0 | 5 votes |
public synchronized void onRefresh(boolean isRefresh) { MenuItem refreshItem = mToolbar.getMenu().findItem(R.id.menu_refresh); if (null != refreshItem) { if (isRefresh) { if (refreshItem.getActionView() == null) { refreshItem.setActionView(R.layout.layout_refresh); ProgressBar progress = (ProgressBar) refreshItem.getActionView().findViewById(R.id.refreshingProgress); if (progress != null) progress.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(this, R.color.color_grey_200), PorterDuff.Mode.SRC_IN); } } else stopRefresh(refreshItem); } }
Example 12
Source File: RefreshAndMoreActivity3.java From YCRefreshView with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem item = menu.findItem(R.id.checkbox); CheckBox box = (CheckBox) item.getActionView(); box.setChecked(true); box.setText("网络"); box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { hasNetWork = isChecked; } }); return true; }
Example 13
Source File: LocationPickerActivity.java From android with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_location_picker, menu); MenuItem searchItem = menu.findItem(R.id.search); if (searchItem != null) { SearchView sv = (SearchView) searchItem.getActionView(); sv.setSubmitButtonEnabled(false); sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return true; } @Override public boolean onQueryTextChange(String newText) { if (TextUtils.isEmpty(newText)) { mPresenter.filter(null); } else { mPresenter.filter(newText); } return true; } }); } return true; }
Example 14
Source File: FragmentContacts.java From FairEmail with GNU General Public License v3.0 | 5 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_contacts, menu); MenuItem menuSearch = menu.findItem(R.id.menu_search); SearchView searchView = (SearchView) menuSearch.getActionView(); searchView.setQueryHint(getString(R.string.title_search)); if (!TextUtils.isEmpty(searching)) { menuSearch.expandActionView(); searchView.setQuery(searching, true); } searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { searching = newText; adapter.search(newText); return true; } @Override public boolean onQueryTextSubmit(String query) { searching = query; adapter.search(query); return true; } }); super.onCreateOptionsMenu(menu, inflater); }
Example 15
Source File: IndeterminateProgressActivity.java From RefreshActionItem-Native with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.refresh, menu); MenuItem item = menu.findItem(R.id.refresh_button); mRefreshActionItem = (RefreshActionItem)item.getActionView(); mRefreshActionItem.setMenuItem(item); mRefreshActionItem.setProgressIndicatorType(ProgressIndicatorType.INDETERMINATE); mRefreshActionItem.setRefreshActionListener(this); loadData(); return true; }
Example 16
Source File: SearchActivity.java From WanAndroid with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_search, menu); MenuItem menuItem = menu.findItem(R.id.item_search); //得到SearchView mSearchView = (SearchView)menuItem.getActionView(); mSearchAutoComplete = mSearchView.findViewById(R.id.search_src_text); mSearchView.setMaxWidth(R.dimen.dp_400);//设置最大宽度 mSearchView.setSubmitButtonEnabled(true);//设置是否显示搜索框展开时的提交按钮 mSearchView.setQueryHint(getResources().getString(R.string.searchActivity_hint));//设置输入框提示语 mSearchView.onActionViewExpanded();//设置搜索框直接展开显示。左侧有放大镜(在搜索框中) 右侧无叉叉 有输入内容后有叉叉 不能关闭搜索框 mSearchAutoComplete.setTextColor(getResources().getColor(R.color.white));//设置内容文字颜色 //搜索框文字变化监听,搜索按钮监听 mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { mPresenter.addHistoryRecord(query); mPresenter.loadSearchResquest(query, 0); isLoadMore = false; return false; } @Override public boolean onQueryTextChange(String newText) { mPresenter.clearAllSearchKey(newText); return false; } }); return super.onCreateOptionsMenu(menu); }
Example 17
Source File: CatalogFragment.java From Ouroboros with GNU General Public License v3.0 | 4 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){ inflater.inflate(R.menu.menu_catalog, menu); MenuItem replyButton = menu.findItem(R.id.action_reply); MenuItem openExternalButton = menu.findItem(R.id.action_external_browser); MenuItem menuLayout = menu.findItem(R.id.action_menu_layout); MenuItem shareButton = menu.findItem(R.id.menu_item_share); MenuItem sortBy = menu.findItem(R.id.action_sort_by); replyButton.setVisible(true); openExternalButton.setVisible(true); menuLayout.setVisible(true); sortBy.setVisible(true); shareButton.setVisible(true); shareActionProvider = MenuItemCompat.getActionProvider(shareButton); MenuItem searchButton = menu.findItem(R.id.action_search); searchButton.setVisible(true); SearchView searchView = (SearchView) searchButton.getActionView(); searchView.setIconifiedByDefault(false); searchView.setSubmitButtonEnabled(false); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { Log.d(LOG_TAG, "query=" + newText); catalogAdapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence constraint) { return infiniteDbHelper.searchCatalogForThread(constraint.toString(), SettingsHelper.getSortByMethod(getContext())); } }); catalogAdapter.getFilter().filter(newText); return true; } }); }
Example 18
Source File: GlobalSearchFragment.java From Android-Remote with GNU General Public License v3.0 | 4 votes |
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); inflater.inflate(R.menu.global_search_menu, menu); // Create a listener for search change final MenuItem search = menu.findItem(R.id.global_search_menu_search); final SearchView searchView = (SearchView) search.getActionView(); searchView.setIconifiedByDefault(true); searchView.setIconified(false); final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { return false; } @Override public boolean onQueryTextSubmit(String query) { mSwipeRefreshLayout.setRefreshing(true); mEmptyView.setRefreshing(true); Message msg = Message.obtain(); msg.obj = ClementineMessageFactory.buildGlobalSearch(query); App.ClementineConnection.mHandler.sendMessage(msg); hideSoftInput(); // Set the actionbar title mActionBar.setTitle(getResources().getString(R.string.global_search_query, query)); mActionBar.setSubtitle("/"); // Query must be empty in order to collapse the search view. searchView.setQuery("", false); searchView.setIconified(true); // Remove currently present adapters mAdapters.clear(); showList(); return true; } }; searchView.setOnQueryTextListener(queryTextListener); searchView.setQueryHint(getString(R.string.global_search_search)); EditText searchText = (EditText) searchView.findViewById( android.support.v7.appcompat.R.id.search_src_text); searchText.setHintTextColor(ContextCompat.getColor(getActivity(), R.color.searchview_edittext_hint)); super.onCreateOptionsMenu(menu, inflater); }
Example 19
Source File: QmsContactsFragment.java From ForPDA with GNU General Public License v3.0 | 4 votes |
@Override protected void addBaseToolbarMenu(Menu menu) { super.addBaseToolbarMenu(menu); toolbar.inflateMenu(R.menu.qms_contacts_menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) searchItem.getActionView(); SearchManager searchManager = (SearchManager) getMainActivity().getSystemService(Context.SEARCH_SERVICE); if (null != searchManager) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getMainActivity().getComponentName())); } searchView.setIconifiedByDefault(true); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { private ArrayList<QmsContactBd> searchContacts = new ArrayList<>(); @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { searchContacts.clear(); if (!newText.isEmpty()) { for (QmsContactBd contact : results) { if (contact.getNick().toLowerCase().contains(newText.toLowerCase())) searchContacts.add(contact); } adapter.addAll(searchContacts); } else { adapter.addAll(results); } return false; } }); searchView.setQueryHint(getString(R.string.user)); menu.add(R.string.blacklist) .setOnMenuItemClickListener(item -> { TabManager.get().add(QmsBlackListFragment.class); return false; }); }
Example 20
Source File: MenuItemCompatHoneycomb.java From guideshow with MIT License | 4 votes |
public static View getActionView(MenuItem item) { return item.getActionView(); }