Last active
December 23, 2015 15:09
-
-
Save mderazon/6654048 to your computer and use it in GitHub Desktop.
how to put the search box in the actionbar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
// ...... | |
// ...... | |
ActionBar actionBar = getSupportActionBar(); // you can use ABS or the non-bc ActionBar | |
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_HOME | |
| ActionBar.DISPLAY_HOME_AS_UP); // what's mainly important here is DISPLAY_SHOW_CUSTOM. the rest is optional | |
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
// inflate the view that we created before | |
View v = inflater.inflate(R.layout.actionbar_search, null); | |
AutoCompleteTextView textView = (AutoCompleteTextView) v.findViewById(R.id.search_box); | |
textView.setAdapter(searchAdapter); | |
textView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | |
@Override | |
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |
// do something when the user clicks | |
} | |
}); | |
actionBar.setCustomView(v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment