Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 4.2.2 makes actionbar icon and title clickable as if part of the same button

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

like image 406
AlikElzin-kilaka Avatar asked Feb 25 '13 16:02

AlikElzin-kilaka


3 Answers

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.

like image 51
i.dun.no Avatar answered Nov 03 '22 04:11

i.dun.no


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.

like image 35
Budius Avatar answered Nov 03 '22 03:11

Budius


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

like image 1
AntonioSanchez Avatar answered Nov 03 '22 03:11

AntonioSanchez