If you're going to use a custom View
in your ActionBar
, you'll need to add it using a different method to make your ImageView
clickable. Here's an example of doing that along with hiding the home affordance.
// Initialize your custom layout
final View v = getLayoutInflater().inflate(R.layout.actionbars, null);
final ImageView iv = (ImageView) v.findViewById(R.id.actionBarLogo);
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Called when your View is clicked
}
});
// Add the custom View to your ActionBar
final ActionBar actionBar = getActionBar();
actionBar.setCustomView(v);
actionBar.setDisplayShowCustomEnabled(true);
// Remove the "up" affordance
actionBar.setDisplayShowHomeEnabled(false);
Your ImageView
isn't a MenuItem
, that's why your app force closes in Activity.onOptionsItemSelected
.