Before 4.2.2, only the logo was clickable.
As of 4.2.2, the title of the actionbar is clickable along with the logo - both as if part of the same button.
You can see an example of this behavior in the Google Reader app - if you have a 4.2.2 device (See screenshot attached).
How do I disable this behavior and enable clicking only on the icon? Perhaps it's a bug?
See example code snippet:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
return true;
}
return false;
}
}
This answer seems related: https://stackoverflow.com/a/16216966/596531
Haven't tried it out myself because it's a workaround at best and complicates my code, but by hiding the real title it should do the trick.
That is not a bug, that's the normal system behaviour! I reckon they changed it so the users can a bigger clickable target area on that button.
Unless you implement your own ActionBar (maybe by extending ActionBar Sherlock) there's nothing you can do about it.
Get rid of:
getActionBar().setHomeButtonEnabled(true);
And (or)
getActionBar().setDisplayHomeAsUpEnabled(true);
That makes the text and the icon clickable with out using
getActionBar().setDisplayHomeAsUpEnabled(true);
except using the code above here ^^ displays a small arrow next to the icon or text
You could try using this
getActionBar().setHomeButtonEnabled(true);
And get rid of the action bar text, my guess... but thats not what you want :/ but it makes just the icon clickable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With