10

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;
    }
}

Clicking on the logo sets the title to also being clicked

3
  • Can you provide a reduced test case that demonstrates the problem in code?
    – Charles
    Commented Feb 25, 2013 at 19:55
  • Have you tried hiding the title and using a custom view instead? Commented Feb 25, 2013 at 20:03
  • @Charles - added qode snippet to the question. As I said, it behaves differently on 4.2.2 than 4.2.1 Commented Feb 26, 2013 at 9:42

3 Answers 3

3

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.

2

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.

7
  • 2
    It is not logical. The title represents the current view. Clicking on it sends the user to the main activity, which was a surprising. If it surprised me, as a developer, it would surprise a lot of users. Commented Feb 26, 2013 at 9:51
  • Also, there was no documentation about this in the release notes, which feels more like a bug. Commented Feb 26, 2013 at 9:51
  • I'm not here to discuss the logic of it. I'm just telling you that this is the platform new standard behaviour and unless you can convince the guys in Mountain View to change it back, that's how it will be.
    – Budius
    Commented Feb 26, 2013 at 9:53
  • 1
    Intentionally or not, how do I return back to the original convention? Why do I think there is nothing I can do about it? Can you reference to the code where separating the icon and the title is not possible? Commented Feb 26, 2013 at 9:57
  • 1
    and I'm telling you to either get over it or develop your own action bar!
    – Budius
    Commented Feb 26, 2013 at 10:41
1

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


EDIT

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.