I'm using AppCompat and trying to recall the ImageView
for the up/back button belonging to the toolbar.
I know R.android.id.home
exists, because I can manage its click as a Menu item:
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
//this works
}
return super.onOptionsItemSelected(item);
}
Apart from that, whenever I try to call findViewById(android.R.id.home)
- be it onCreate
, be it onClick
of a custom button - I get null.
I even get null if, in the sample above, I call findViewById(item.getItemId())
.
Why is it? This question has been asked before here, most times regarding ActionBarSherlock (which I am not using). Another time it was suggested to use:
getWindow().getDecorView().findViewById(android.R.id.home)
But it isn't working. In that question the OP also says findViewById(android.R.id.home)
works on API>3.0, but that's not true for me. Any ideas?