Java Code Examples for android.support.v7.widget.SearchView#setQueryHint()

The following examples show how to use android.support.v7.widget.SearchView#setQueryHint() . 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: SearchActivity.java    From playa with MIT License 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.search, menu);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setQueryHint(getString(R.string.search_view_hint));
    searchView.onActionViewExpanded();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            // 跳转到搜索 fragment ,同时传入关键词
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container,
                            SearchResultFragment.newInstance(query.toString()))
                    .commit();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    return super.onCreateOptionsMenu(menu);
}
 
Example 2
Source File: QuestionsActivity.java    From mvp-android-arch-component with MIT License 6 votes vote down vote up
@Override public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.questions, menu);

  // Setup search widget in action bar
  SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
  searchView.setQueryHint(getString(R.string.search_hint));
  searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);

  searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override public boolean onQueryTextSubmit(String query) {
      return false;
    }

    @Override public boolean onQueryTextChange(String newText) {
      presenter.search(newText);
      return true;
    }
  });

  return true;
}
 
Example 3
Source File: MainActivity.java    From Jide-Note with MIT License 6 votes vote down vote up
/**
 * 创建Menu按键的菜单
 * @param menu
 * @return
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setQueryHint("搜索笔记内容");
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            LogUtils.e("onQueryTextSubmit  ==  " + query);
            queryNote(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            LogUtils.e("onQueryTextChange  ==  " + newText);
            if (newText.equals("")) {
                resumeNote();
            }
            return false;
        }
    });
    return true;
}
 
Example 4
Source File: SearchMusicActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search_music, menu);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setMaxWidth(Integer.MAX_VALUE);
    searchView.onActionViewExpanded();
    searchView.setQueryHint(getString(R.string.search_tips));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            searchMusic(query);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    searchView.setSubmitButtonEnabled(true);
    try {
        Field field = searchView.getClass().getDeclaredField("mGoButton");
        field.setAccessible(true);
        ImageView mGoButton = (ImageView) field.get(searchView);
        mGoButton.setImageResource(R.drawable.ic_menu_search);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return super.onCreateOptionsMenu(menu);
}
 
Example 5
Source File: ProductsFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.product_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.product_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 6
Source File: OrdersFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.order_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.order_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 7
Source File: MainActivity.java    From PopCorn with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);

    final MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setQueryHint(getResources().getString(R.string.search_movies_tv_shows_people));

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (!NetworkConnection.isConnected(MainActivity.this)) {
                Toast.makeText(MainActivity.this, R.string.no_network, Toast.LENGTH_SHORT).show();
                return true;
            }
            Intent intent = new Intent(MainActivity.this, SearchActivity.class);
            intent.putExtra(Constants.QUERY, query);
            startActivity(intent);
            searchMenuItem.collapseActionView();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });

    return true;
}
 
Example 8
Source File: AppChoicesActivity.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.app_search, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_app_search);
    MenuItem filterEnabledAppsItem = menu.findItem(R.id.menu_filter_enabled);

    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setQueryHint(getString(R.string.search_query_hint));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return recyclerViewShowSearchResult(query);
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return recyclerViewShowSearchResult(newText);
        }
    });

    searchItem.setEnabled(false);
    filterEnabledAppsItem.setEnabled(false);
    filterEnabledAppsItem.setChecked(mShowOnlyEnabledApps);

    return true;
}
 
Example 9
Source File: SearchActivity.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.search_menu_setting, menu);
    MenuItem menuItem = menu.findItem(R.id.menu_search);
    //获取搜索框
    mSearchView = (SearchView) menuItem.getActionView();
    //设置搜索hint
    mSearchView.setQueryHint(getString(R.string.search_keyword));
    mSearchView.onActionViewExpanded();
    //去除搜索框背景
    deleteSearchPlate();
    searchAutoComplete =  mSearchView.findViewById(R.id.search_src_text);
    searchAutoComplete.setHintTextColor(ContextCompat.getColor(this, R.color._60ffffff));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ImageView mCloseView =  mSearchView.findViewById(R.id.search_close_btn);
        mCloseView.setBackground(ContextCompat.getDrawable(this, R.drawable.ripple_close));
    }

    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            keyword = query;
            refreshData();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (TextUtils.isEmpty(newText)) {
                keyword = newText;
                if (mHotwordDatas.size() == 0)
                    loadTagDatas();
            }

            return false;
        }
    });
    return super.onCreateOptionsMenu(menu);
}
 
Example 10
Source File: MainActivity.java    From moviedb-android with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the contents of the Activity's standard options menu.
 * This is only called once, the first time the options menu is displayed.
 *
 * @param menu the options menu in which we place our items.
 * @return You must return true for the menu to be displayed; if you return false it will not be shown.
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    searchViewItem = menu.findItem(R.id.search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchViewItem);

    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    searchView.setOnQueryTextListener(searchViewOnQueryTextListener);
    searchView.setOnSuggestionListener(searchSuggestionListener);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager =
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchViewItemC =
            (SearchView) menu.findItem(R.id.search).getActionView();
    searchViewItemC.setSearchableInfo(
            searchManager.getSearchableInfo(getComponentName()));


    String[] from = {SearchManager.SUGGEST_COLUMN_ICON_1, SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2};
    int[] to = {R.id.posterPath, R.id.title, R.id.info};
    searchAdapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.suggestionrow, null, from, to, 0) {
        @Override
        public void changeCursor(Cursor cursor) {
            super.swapCursor(cursor);
        }
    };
    searchViewItemC.setSuggestionsAdapter(searchAdapter);

    MenuItemCompat.setOnActionExpandListener(searchViewItem, onSearchViewItemExpand);


    return true;
}
 
Example 11
Source File: CaptureListFragment.java    From CapturePacket with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    if (mRootView == null) {
        mRootView = inflater.inflate(R.layout.fragment_capture_list, container, false);
        Toolbar toolBar = mRootView.findViewById(R.id.tool_bar);
        toolBar.inflateMenu(R.menu.capture_list_bar);
        toolBar.setOnMenuItemClickListener(this);
        MenuItem item = toolBar.getMenu().findItem(R.id.filter);
        mSearchView = (SearchView) item.getActionView();
        mSearchView.setQueryHint("过滤Url");
        mSearchView.setOnQueryTextListener(this);

        mRecyclerView = mRootView.findViewById(R.id.recycler_view);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(null,LinearLayoutManager.VERTICAL,false));
        mHandler  = new RefreshHandler(this);
        mAdapter = new CaptureListAdapter();
        if (mCaptureBinder != null) {
            mAdapter.setHarEntries(mCaptureBinder.getHarEntries());
        }
        mRecyclerView.setAdapter(mAdapter);
        EntryTabDelegate tabDelegate = new EntryTabDelegate((TabLayout) mRootView.findViewById(R.id.tab), (ViewGroup) mRootView.findViewById(R.id.fl_detail));
        tabDelegate.setRefreshHandler(mHandler);
        mAdapter.setEntryTabDelegate(tabDelegate);
    }
    return mRootView;
}
 
Example 12
Source File: FloatViewWhiteListActivity.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        getMenuInflater().inflate(R.menu.white_list_activity_menu, menu);
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        final SearchView searchView = (SearchView) menu.findItem(R.id.ab_search).getActionView();

        selectAll = menu.findItem(R.id.select_all);
        setSelection = menu.findItem(R.id.setSelection);

        final SearchView.SearchAutoComplete searchEditText = searchView.findViewById(R.id.search_src_text);

        searchEditText.setTextColor(getResources().getColor(R.color.white));
        searchView.setQueryHint("Search");

        // 将搜索按钮放到搜索输入框的外边
        searchView.setIconifiedByDefault(false);


        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                refreshListByQuery(searchView.getQuery().toString());
                return true;
            }
        });
        searchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override
            public boolean onClose() {
                refreshListByQuery("");
                return false;
            }
        });

    }
    refreshMenu(false);
    return true;
}
 
Example 13
Source File: WhiteListActivity.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            getMenuInflater().inflate(R.menu.white_list_activity_menu, menu);
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            final SearchView searchView = (SearchView) menu.findItem(R.id.ab_search).getActionView();

            selectAll = menu.findItem(R.id.select_all);
            setSelection = menu.findItem(R.id.setSelection);

            final SearchView.SearchAutoComplete searchEditText = searchView.findViewById(R.id.search_src_text);

            searchEditText.setTextColor(getResources().getColor(R.color.white));
            searchView.setQueryHint("Search");

            // 将搜索按钮放到搜索输入框的外边
            searchView.setIconifiedByDefault(false);


            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    refreshListByQuery(searchView.getQuery().toString());
                    return true;
                }
            });
            searchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    refreshListByQuery("");
                    return false;
                }
            });

//            MenuItem menuItem=menu.add("恢复默认");
//            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
//            menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
//                @Override
//                public boolean onMenuItemClick(MenuItem item) {
//                    if(mSelectedApplicationInfos==null){
//                        SnackBarUtil.show(toolbar,R.string.wait_until_loaded);
//                        return true;
//                    }
//                    for (AppListAdapter.ApplicationInfoWrap app:mSelectedApplicationInfos){
//                        app.isSelected=false;
//                    }
//                    mSelectedApplicationInfos.clear();
//                    mAppAdapter.notifyDataSetChanged();
//                    refreshTV();
//                    return true;
//                }
//            });
        }
        setSelection.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                showPopupMenu(toolbar);
                return true;
            }
        });
        refreshMenu(false);
        return true;
    }
 
Example 14
Source File: XposedAppManagerActivity.java    From timecat with Apache License 2.0 4 votes vote down vote up
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            getMenuInflater().inflate(R.menu.white_list_activity_menu, menu);
            SearchManager searchManager =
                    (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            final SearchView searchView = (SearchView) menu.findItem(R.id.ab_search).getActionView();

            selectAll=menu.findItem(R.id.select_all);
            setSelection=menu.findItem(R.id.setSelection);

            final SearchView.SearchAutoComplete searchEditText = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);

            searchEditText.setTextColor(getResources().getColor(R.color.white));
            searchView.setQueryHint("Search");

            // 将搜索按钮放到搜索输入框的外边
            searchView.setIconifiedByDefault(false);


            searchView.setSearchableInfo(
                    searchManager.getSearchableInfo(getComponentName()));
            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    refreshListByQuery(searchView.getQuery().toString());
                    return true;
                }
            });
            searchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    refreshListByQuery("");
                    return false;
                }
            });

//            MenuItem menuItem=menu.add("恢复默认");
//            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
//            menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
//                @Override
//                public boolean onMenuItemClick(MenuItem item) {
//                    if(mSelectedApplicationInfos==null){
//                        SnackBarUtil.show(toolbar,R.string.wait_until_loaded);
//                        return true;
//                    }
//                    for (AppListAdapter.ApplicationInfoWrap app:mSelectedApplicationInfos){
//                        app.isSelected=false;
//                    }
//                    mSelectedApplicationInfos.clear();
//                    mAppAdapter.notifyDataSetChanged();
//                    refreshTV();
//                    return true;
//                }
//            });
        }
        setSelection.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                showPopupMenu(toolbar);
                return true;
            }
        });
        refreshMenu(false);
        return true;
    }
 
Example 15
Source File: MainActivity.java    From writeily-pro with MIT License 4 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);

    final MenuItem searchItem = menu.findItem(R.id.action_search);

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    if (searchView != null) {
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                if (query != null) {
                    if (notesFragment.isVisible())
                        notesFragment.search(query);
                }
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                if (newText != null) {
                    if (notesFragment.isVisible()) {
                        if (newText.equalsIgnoreCase("")) {
                            notesFragment.clearSearchFilter();
                        } else {
                            notesFragment.search(newText);
                        }
                    }
                }
                return false;
            }
        });

        searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {

                menu.findItem(R.id.action_import).setVisible(false);
                menu.findItem(R.id.action_settings).setVisible(false);

                if (!hasFocus) {
                    menu.findItem(R.id.action_import).setVisible(true);
                    menu.findItem(R.id.action_settings).setVisible(true);
                    searchItem.collapseActionView();
                    searchView.setQuery("", false);
                }
            }
        });

        searchView.setQueryHint(getString(R.string.search_hint));
    }

    return true;
}
 
Example 16
Source File: PlaylistFragment.java    From Android-Remote with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onPrepareOptionsMenu(Menu menu) {
    // Create a listener for search change
    SearchView searchView = (SearchView) menu.findItem(R.id.playlist_menu_search)
            .getActionView();

    final SearchView.OnQueryTextListener queryTextListener
            = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            // Set the filter text as the fragments might not yet
            // created. Only the left and right fragment from the
            // currently active is created (onCreate() called).
            // Therefore the other adapters are not yet created,
            // onCreate filters for this string given in setFilterText()
            setFilterText(newText);
            if (getAdapter() != null) {
                getAdapter().getFilter().filter(newText);
            }
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            // Do something
            setFilterText(query);
            if (getAdapter() != null) {
                getAdapter().getFilter().filter(query);
            }

            return true;
        }
    };
    searchView.setOnQueryTextListener(queryTextListener);
    searchView.setQueryHint(getString(R.string.playlist_search_hint));

    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.onPrepareOptionsMenu(menu);
}
 
Example 17
Source File: MainActivity.java    From AndroidHttpCapture with MIT License 4 votes vote down vote up
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);

//        MenuItem pageButton = menu.findItem(R.id.action_page);
//        pageButton.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
//            @Override
//            public boolean onMenuItemClick(MenuItem item) {
//                createPage();
//                return true;
//            }
//        });

        filterMenuItem = menu.findItem(R.id.action_filter);
        homeItem = menu.findItem(R.id.action_home);
        searchItem = menu.findItem(R.id.search);
//        uaMenuItem = menu.findItem(R.id.ua);
//        logMenuItem = menu.findItem(R.id.log);

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchView = (SearchView) searchItem.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setFocusable(false);
        searchView.setIconifiedByDefault(true);
        searchView.setMaxWidth(Integer.MAX_VALUE);
        searchView.setQueryHint("请输入URL关键字...");

        searchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switchContent(PreviewFragment.getInstance());
            }
        });

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                PreviewFragment.getInstance().filterItem(query);
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                PreviewFragment.getInstance().filterItem(newText);
                shouldExitSearchView = newText.length() == 0;
                return false;
            }
        });
        return true;
    }
 
Example 18
Source File: MainActivity.java    From memetastic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.main__menu, menu);
    updateSearchFilter("");
    boolean isCreateTab = _bottomNav.getSelectedItemId() == R.id.nav_mode_create;
    menu.findItem(R.id.action_picture_from_camera).setVisible(isCreateTab);
    menu.findItem(R.id.action_picture_from_gallery).setVisible(isCreateTab);
    menu.findItem(R.id.action_search_meme).setVisible(isCreateTab);

    _searchItem = menu.findItem(R.id.action_search_meme);
    _searchView = (SearchView) _searchItem.getActionView();

    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    _searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    _searchView.setQueryHint(getString(R.string.search_meme__appspecific));
    if (_searchView != null) {
        _searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                if (query != null) {
                    updateSearchFilter(query);
                }
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                if (newText != null) {
                    updateSearchFilter(newText);
                }
                return false;
            }
        });
        _searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
            if (!hasFocus) {
                _searchItem.collapseActionView();
                updateSearchFilter("");
            }
        });
    }
    return true;
}
 
Example 19
Source File: QmsContactsFragment.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
@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: GlobalSearchFragment.java    From Android-Remote with GNU General Public License v3.0 4 votes vote down vote up
@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);
}