Reputation: 1653
look this image:
When you click on the "Action bar" string my app enter in this method:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
So also it is an item, the problem is that i don't know which id it has.
Where can i get the id of this item ?
Upvotes: 0
Views: 47
Reputation: 21
Try this:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
case android.R.id.home:
//here you put your code
Toast.makeText(this, "You click Action Bar", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Upvotes: 1
Reputation: 18977
android.R.id.home
if you have set
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
Upvotes: 1