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

The following examples show how to use android.support.v7.widget.SearchView#onActionViewExpanded() . 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: SearchFragment.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initView() {
    mToolbar.inflateMenu(R.menu.menu_search);
    mToolbar.setNavigationIcon(R.drawable.ic_nav_back);
    mToolbar.setNavigationOnClickListener(v -> pop());

    MenuItem item = mToolbar.getMenu().findItem(R.id.action_search);
    mSearchView = (SearchView) item.getActionView();
    mSearchView.setQueryHint("输入关键字");
    mSearchView.onActionViewExpanded();
    /*SearchManager searchManager = (SearchManager)getActivity().getSystemService(SEARCH_SERVICE);
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));*/

    mHistoryAdapter = new SearchHistoryAdapterWithThirdLib();
    mHistoryRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mHistoryRecyclerView.setAdapter(mHistoryAdapter);
    mEmptyView = getLayoutInflater().inflate(R.layout.view_empty, (ViewGroup) mHistoryRecyclerView.getParent(), false);
    mEmptyTipsView = mEmptyView.findViewById(R.id.txt_tips);
    mEmptyTipsView.setText("暂无搜索历史");
}
 
Example 3
Source File: SearchActivity.java    From Toutiao with Apache License 2.0 6 votes vote down vote up
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_search, menu);
        MenuItem item = menu.findItem(R.id.action_search);
        searchView = (SearchView) MenuItemCompat.getActionView(item);
        // 关联检索配置与 SearchActivity
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchableInfo searchableInfo = searchManager.getSearchableInfo(
                new ComponentName(getApplicationContext(), SearchActivity.class));
        searchView.setSearchableInfo(searchableInfo);
        searchView.onActionViewExpanded();
//        // 设置搜索文字样式
//        EditText searchEditText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
//        searchEditText.setTextColor(getResources().getColor(R.color.textColorPrimary));
//        searchEditText.setHintTextColor(getResources().getColor(R.color.textColorPrimary));
//        searchEditText.setBackgroundColor(Color.WHITE);
        setOnQuenyTextChangeListener();

        return super.onCreateOptionsMenu(menu);
    }
 
Example 4
Source File: SearchActivity.java    From Paperwork-Android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    setSupportActionBar(toolbar);

    if (getSupportActionBar() != null)
    {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mNotesFragment = (NotesFragment) Fragment.instantiate(SearchActivity.this, NotesFragment.class.getName());
    Bundle bundle = new Bundle();
    bundle.putBoolean(NotesFragment.KEY_SEARCH_MODE, true);
    mNotesFragment.setArguments(bundle);
    (getFragmentManager().beginTransaction().replace(R.id.main_container, mNotesFragment)).commit();

    SearchView searchView = (SearchView) findViewById(R.id.search);
    searchView.onActionViewExpanded();
    searchView.setOnQueryTextListener(this);
}
 
Example 5
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 6
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 7
Source File: searchActivity.java    From music_player with Open Software License 3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.search_menu, menu);
    MenuItem search = menu.findItem(R.id.search_menu);
    searchView = (SearchView) MenuItemCompat.getActionView(search);
    searchView.onActionViewExpanded();
    searchView.setOnQueryTextListener(this);
    return super.onCreateOptionsMenu(menu);
}