Reputation: 3043
How can I get on click action, when I clicked actionbar logo. I tried
onOptionsItemSelected
case android.R.id.home://here to get action
and it does not work. I tried to add onClick listener on my decor view like this at onCreate
getWindow().getDecorView().setOnClickListener(this);
getWindow().getDecorView().setOnTouchListener(this);
getWindow().getDecorView().getRootView().setOnClickListener(this);
getWindow().getDecorView().getRootView().setOnTouchListener(this);
and I implemented simple listener
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Toast.makeText(this, "onTouch pressed", Toast.LENGTH_LONG).show();
return false;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(this, "onClick pressed", Toast.LENGTH_LONG).show();
}
But it does not enter none of the methods. How can I get OnClick action on icon or onclick action when user clicked at Top Left corner of my decorview
Upvotes: 2
Views: 2309
Reputation: 28239
First set the logo to be a clickable button:
myActionBar.setHomeButtonEnabled(true);
Then, override this method to get clicks:
public boolean onMenuItemSelected(int featureId, MenuItem item)
Upvotes: 3