Skip to content

Instantly share code, notes, and snippets.

@abhinavraj23
Created September 28, 2019 20:12
Show Gist options
  • Save abhinavraj23/01643c1a3c4427c9b15e611f03e873b5 to your computer and use it in GitHub Desktop.
Save abhinavraj23/01643c1a3c4427c9b15e611f03e873b5 to your computer and use it in GitHub Desktop.
searchBar.setOnSearchActionListener(new SearchBar.OnSearchActionListener() {
@Override
public void onSearchStateChanged(boolean enabled) {
String state = enabled ? "enabled" : "disabled";
Toast.makeText(getApplicationContext(), "Search bar is " + state, Toast.LENGTH_SHORT).show();
}
@Override
public void onSearchConfirmed(CharSequence text) {
Toast.makeText(getApplicationContext(), "Search query is: " + text, Toast.LENGTH_SHORT).show();
}
@Override
public void onButtonClicked(int buttonCode) {
switch (buttonCode) {
case SearchBar.BUTTON_BACK:
Toast.makeText(getApplicationContext(), "Back button pressed", Toast.LENGTH_SHORT).show();
break;
case SearchBar.BUTTON_NAVIGATION:
Toast.makeText(getApplicationContext(), "Open Navigation Drawer", Toast.LENGTH_SHORT).show();
break;
case SearchBar.BUTTON_SPEECH:
// Yet to come
Toast.makeText(getApplicationContext(), "Start voice recognition module", Toast.LENGTH_SHORT).show();
break;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment