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

x33g5p2x  于2022-01-30 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(136)

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

SearchView.clearFocus介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setIconified(false);
searchView.clearFocus();

代码示例来源:origin: stackoverflow.com

private SearchView searchView;

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.search_menu, menu);
  searchView = (SearchView) menu.findItem(R.id.menu_search)
      .getActionView(); // set the reference to the searchView
  searchView.setOnQueryTextListener(this); 
  searchMenuItem = (MenuItem) menu.findItem(R.id.menu_search); 
  searchMenuItem.expandActionView(); // expand the search action item automatically
  searchView.setQuery("<put your search term here>", false); // fill in the search term by default
  searchView.clearFocus(); // close the keyboard on load
  return true;
}

@Override
public boolean onQueryTextSubmit(String query) {
  performNewSearch(query);
  searchView.clearFocus();
  return true;
}

代码示例来源:origin: gigabytedevelopers/FireFiles

@Override
public boolean onQueryTextSubmit(String query) {
  mSearchExpanded = true;
  mState.currentSearch = query;
  mSearchView.clearFocus();
  onCurrentDirectoryChanged(ANIM_NONE);
  return true;
}
@Override

代码示例来源:origin: stackoverflow.com

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main_activity);

  //Define your Searchview
  SearchView searchView = (SearchView) findViewById(R.id.search_bar);

  //Turn iconified to false:
  searchView.setIconified(false);
  //The above line will expand it to fit the area as well as throw up the keyboard

  //To remove the keyboard, but make sure you keep the expanded version:
  searchView.clearFocus();
}

代码示例来源:origin: SunAlwaysOnline/Sukeda

@Override
public boolean onQueryTextSubmit(String s) {
  //book_list=null;
  BookUtil.page = 1;
  BookUtil.all_books = 0;
  initData(s);
  setAblExpanded(false);
  //搜索后失去焦点
  searchView.clearFocus();
  return false;
}

代码示例来源:origin: stackoverflow.com

MenuItem searchItem = menu.findItem(R.id.menu_item_search);
SearchView mSearchView = (SearchView) menu.findItem(R.id.menu_item_search).getActionView();
    if (mSearchView!=null && searchItem!=null) {
      mSearchView.clearFocus();
      searchItem.collapseActionView();
    }

代码示例来源:origin: algolia/instantsearch-android

/**
 * Called when this view wants to give up focus. If focus is cleared
 * {@link View#onFocusChanged(boolean, int, android.graphics.Rect)} is called.
 * <p>
 * <strong>Note:</strong> When a View clears focus the framework is trying
 * to give focus to the first focusable View from the top. Hence, if this
 * View is the first from the top that can take focus, then all callbacks
 * related to clearing focus will be invoked after which the framework will
 * give focus to this view.
 * </p>
 */
public void clearFocus() {
  if (searchView != null) {
    searchView.clearFocus();
  } else if (supportView != null) {
    supportView.clearFocus();
  } else {
    throw new IllegalStateException(ERROR_NO_SEARCHVIEW);
  }
}

代码示例来源:origin: stackoverflow.com

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
  searchView.setIconified(false);
  searchView.setIconifiedByDefault(false);
  searchView.clearFocus();
  }
}

代码示例来源:origin: stackoverflow.com

@Override
 public void onPrepareOptionsMenu(Menu menu) {
   final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
   if(!TextUtils.isEmpty(mSearch)){
     searchView.setQuery(mSearch, false);
     searchView.setIconified(false);
     searchView.clearFocus();
   }
 }

代码示例来源:origin: stackoverflow.com

SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
searchView.clearFocus();
View focused = searchView.getFocusedChild();
if (focused != null) {
  focused.clearFocus();
}

代码示例来源:origin: WeAreFairphone/FP2-Launcher

protected void hideKeyboard() {
  InputMethodManager imm = (InputMethodManager) mLauncher.getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(mSearchView.getApplicationWindowToken(), 0);
  mIsKeyboardShowing = false;
  mSearchView.clearFocus();
  mDrawerView.findViewById(R.id.agingDrawerScroll).requestFocusFromTouch();
}

代码示例来源:origin: msahakyan/nested-recycler-view

private void handleIntent(Intent intent) {
  if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
    String query = intent.getStringExtra(SearchManager.QUERY);
    //  Saving the query during of on handle intent
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
      SearchSuggestionsProvider.AUTHORITY, SearchSuggestionsProvider.MODE);
    suggestions.saveRecentQuery(query, null);
    try {
      query = URLEncoder.encode(query, "utf-8");
    } catch (UnsupportedEncodingException e) {
      Log.w(TAG, "Can't encode search query", e);
    }
    initSearchEndpointAndUrlParams(query);
    mDialog.setMessage(getString(R.string.loading_more_data));
    mDialog.getWindow().setGravity(Gravity.CENTER);
    mDialog.show();
    loadSearchResults();
    mSearchView.clearFocus();
  }
}

代码示例来源:origin: stackoverflow.com

public boolean onQueryTextSubmit(String s) {
  Log.i(TAG,"onQueryTextSubmit: " + s);
  searchView.clearFocus();
  return true;

代码示例来源:origin: stackoverflow.com

final SearchView sv = new SearchView(((MainActivity) getActivity()).getSupportActionBar().getThemedContext());
   sv.setIconifiedByDefault(true);
   sv.setFocusable(true);
   sv.setIconified(false);
   sv.clearFocus();
   sv.requestFocusFromTouch();

代码示例来源:origin: gigabytedevelopers/FireFiles

search.expandActionView();
  mSearchView.setIconified(false);
  mSearchView.clearFocus();
  mSearchView.setQuery(mState.currentSearch, false);
} else {
  mIgnoreNextClose = true;
  mSearchView.setIconified(true);
  mSearchView.clearFocus();
  mIgnoreNextCollapse = true;
  search.collapseActionView();

代码示例来源:origin: SunAlwaysOnline/Sukeda

@Override
public boolean onQueryTextSubmit(String query) {
  sv_phone.clearFocus();
  ShowDialogUtil.showProgressDialog(getActivity(), "正在查询...");
  PhoneUtil.get_phone(query, new PhoneUtil.getPhone_mohuCall() {
    @Override
    public void success(final List<DepartmentPhone> list) {
      ShowDialogUtil.closeProgressDialog();
      new MaterialDialog.Builder(getActivity())
          .title("点击即可跳转到拨号界面")
          .negativeText("取消")
          .items(list)
          .itemsCallback(new MaterialDialog.ListCallback() {
            @Override
            public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
              Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + list.get(position).getPhone()));
              getActivity().startActivity(i);
            }
          })
          .show();
    }
    @Override
    public void fail() {
    }
  });
  return false;
}

代码示例来源:origin: stackoverflow.com

searchView.clearFocus();

代码示例来源:origin: stackoverflow.com

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
   // Inflate the menu; this adds items to the action bar if it is present.
   getMenuInflater().inflate(R.menu.my_list, menu);
   final MenuItem searchItem = menu.findItem(R.id.action_search);
   final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
   searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
     @Override
     public boolean onQueryTextSubmit(String query) {
       //Fetch the data remotely
       FetchData(query);
       //Reset the SearchView
       searchView.clearFocus();
       searchView.setQuery("", false);
       searchView.setIconified(true);
       searchItem.collapseActionView();
       //Set Activity title to search query
       MainActivity.this.setTitle(query);
       return true;
     }
     @Override
     public boolean onQueryTextChange(String newText) {
       return false;
     }
   });
   return true;
 }

代码示例来源:origin: SunAlwaysOnline/Sukeda

public void onBackPressed() {
  int count = getSupportFragmentManager().getBackStackEntryCount();
  if (count == 1) {
    String tag = getSupportFragmentManager().getBackStackEntryAt(0).getName();
    super.onBackPressed();
    searchView.setVisibility(View.VISIBLE);
    searchView.clearFocus();
    recyclerView.setVisibility(View.VISIBLE);
    if (tag != null && tag.equals("detail")) {
      return;
    }
    if (abl_library != null) {
      setAblExpanded(true);
    }
    return;
  }
  if (count == 0) {
    if (abl_state != STATE.EXPANDED) {
      setAblExpanded(true);
    } else {
      startActivity(new Intent(LibraryActivity.this, HomeActivity.class));
      overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
      super.onBackPressed();
    }
  }
}

代码示例来源:origin: ValueYouth/RhymeMusic

private void initComponents()
  {
    application = (MusicApplication) getApplication();

    /*搜索结果为空时,显示的提示信息*/
    textTips = (TextView) findViewById(R.id.text_tips);

    /*按钮类组件初始化*/
    searchBack = (ImageButton) findViewById(R.id.image_search_back);
    searchOption = (ImageButton) findViewById(R.id.image_search_option);
    searchBack.setOnClickListener(this);
    searchOption.setOnClickListener(this);

    /*列表组件初始化*/
    listView = (ListView) findViewById(R.id.list_search_result);
    listView.setOnItemClickListener(this);
    listView.setVisibility(View.INVISIBLE);
    loadData();

    /*搜索组件初始化*/
    searchView = (SearchView) findViewById(R.id.view_search);
    searchView.setOnQueryTextListener(this);
    searchView.onActionViewExpanded(); // 默认出现点击输入状态
    searchView.setFocusable(false);
    searchView.clearFocus();
//        searchView.setSubmitButtonEnabled(true);

  }

相关文章