android.support.v7.widget.SearchView.onActionViewExpanded()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中android.support.v7.widget.SearchView.onActionViewExpanded()方法的一些代码示例,展示了SearchView.onActionViewExpanded()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SearchView.onActionViewExpanded()方法的具体详情如下:
包路径:android.support.v7.widget.SearchView
类名称:SearchView
方法名:onActionViewExpanded

SearchView.onActionViewExpanded介绍

暂无

代码示例

代码示例来源:origin: iMeiji/Toutiao

@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);
  }

代码示例来源:origin: wenhuaijun/EasyImageLoader

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch(item.getItemId()){
    case R.id.action_search:
      searchView.setVisibility(View.VISIBLE);
      searchView.onActionViewExpanded();
      searchView.requestFocus();
      break;
    case R.id.action_linearLayout:
      layoutSysle =Constants.LinearLayoutStyle;
      recyclerAdapter.setLayoutManagerType(layoutSysle);
      recyclerView.setLayoutManager(new LinearLayoutManager(this));
      break;
    case R.id.action_stageGridLayout:
      layoutSysle =Constants.StagedGridLayoutStyle;
      recyclerAdapter.setLayoutManagerType(layoutSysle);
      recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
      break;
    default:
      return super.onOptionsItemSelected(item);
  }
  return  true;
}

代码示例来源:origin: guanpj/JReadHub

@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("暂无搜索历史");
}

代码示例来源:origin: yangchong211/YCAudioPlayer

@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);
}

代码示例来源:origin: chaychan/MaterialDesignExercise

mSearchView.setQueryHint("输入歌曲名查找");
mSearchView.onActionViewExpanded();// 当展开无输入内容的时候,没有关闭的图标
mSearchView.setIconified(true);//设置searchView处于展开状态

代码示例来源:origin: GitLqr/MaterialDesignDemo

mSearchView.onActionViewExpanded();

代码示例来源:origin: GitLqr/MaterialDesignDemo

mSearchView.onActionViewExpanded();
mSearchView.setIconified(true);

代码示例来源:origin: szpnygo/NoWordsChat

@Override
protected void onCreateDataBinding() {
  super.onCreateDataBinding();
  binding = createContentView(R.layout.activity_add_friend);
  binding.toolbar.setTitle("添加好友");
  setSupportActionBar(binding.toolbar);
  setToolbarFinish(binding.toolbar);
  binding.setUserBean(UserInfoAction.getUserInfo());
  binding.searchView.requestFocus();
  binding.searchView.requestFocusFromTouch();
  binding.searchView.onActionViewExpanded();
  binding.searchView.setSubmitButtonEnabled(true);
  binding.searchView.setIconifiedByDefault(false);
  binding.searchView.setIconified(false);
  binding.searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String query) {
      if (StringUtil.isEmpty(query)) {
        showSnackbarMessage("请输入要查询的无语号");
      } else {
        search(query);
      }
      return false;
    }
    @Override
    public boolean onQueryTextChange(String newText) {
      return false;
    }
  });
}

相关文章