当前位置: 首页>>代码示例>>Java>>正文


Java SearchView.setOnQueryTextFocusChangeListener方法代码示例

本文整理汇总了Java中android.support.v7.widget.SearchView.setOnQueryTextFocusChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java SearchView.setOnQueryTextFocusChangeListener方法的具体用法?Java SearchView.setOnQueryTextFocusChangeListener怎么用?Java SearchView.setOnQueryTextFocusChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.SearchView的用法示例。


在下文中一共展示了SearchView.setOnQueryTextFocusChangeListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.filesystem__menu, menu);

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

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

            @Override
            public boolean onQueryTextChange(String newText) {
                if (newText != null) {
                    if (isVisible()) {
                        if (newText.equalsIgnoreCase("")) {
                            clearSearchFilter();
                        } else {
                            search(newText);
                        }
                    }
                }
                return false;
            }
        });
        _searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
            MenuItem item = menu.findItem(R.id.action_import);
            if (item != null) {
                item.setVisible(hasFocus);
            }
            if (!hasFocus) {
                _searchItem.collapseActionView();
            }
        });
    }
    ContextUtils cu = ContextUtils.get();

    cu.tintMenuItems(menu, true, Color.WHITE);
    cu.setSubMenuIconsVisiblity(menu, true);
}
 
开发者ID:gsantner,项目名称:markor,代码行数:52,代码来源:FilesystemListFragment.java

示例2: onCreateOptionsMenu

import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.main__menu, menu);
    _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.main__search_meme));
    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(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!hasFocus) {
                    _searchItem.collapseActionView();
                    updateSearchFilter("");
                }
            }
        });
    }
    return true;
}
 
开发者ID:gsantner,项目名称:memetastic,代码行数:44,代码来源:MainActivity.java


注:本文中的android.support.v7.widget.SearchView.setOnQueryTextFocusChangeListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。