Android 4.0 / ICS - App Icon on Action Bar not clickable
Asked Answered
I

2

11

For some reason, when testing on my Motorola Xoom with Ice Cream Sandwich, the App Icon in the Action Bar is not clickable, even though I have implemented an event handler. This only occurs after changing the targetSdkVersion to 15. If it is 13 it is still clickable, even on ICS. Why is this happening and how can I make it clickable like a button? I searched the documentation and couldn't find anything.

Thank you.

UPDATE: Here is my code:

AndroidManifest.xml:

...
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
<application android:icon="@drawable/icon" android:label="@string/app_name"
    android:theme="@style/android:Theme.Holo.Light">
...

BaseActivity.java (my activities all inherit from this class:

...
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // app icon in action bar clicked; go home
            Intent intent = new Intent(this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
...
Inspector answered 29/1, 2012 at 3:8 Comment(3)
Tested on the emulator? Is it clickable there?Sena
Just tested it on the emulator, and it's the same as the Xoom; it's not clickable when targetSdkVersion is 15, only when it's 13 (I didn't try 14, but it shouldn't matter).Inspector
@Sena Done. Has anyone else experienced this?Inspector
I
25

I found it in the documentation at http://developer.android.com/guide/topics/ui/actionbar.html:

Note: If you're using the icon to navigate to the home activity, beware that beginning with Android 4.0 (API level 14), you must explicitly enable the icon as an action item by calling setHomeButtonEnabled(true) (in previous versions, the icon was enabled as an action item by default).

Inspector answered 29/1, 2012 at 4:10 Comment(0)
I
0

Would you like to use the following code:

ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
Imbecile answered 12/12, 2013 at 15:45 Comment(2)
Welcome to SO! This question was answered almost two years ago - please edit your answer to give it some context as to why it might be helpful after the OP's problem was solved. Simply presenting code with no additional information isn't useful on Stack Overflow.Decentralize
@Decentralize second that. Why are people re-answering while adding nothing new to the solutions proposed, is beyond me. No action is taken if we report these posts either.Purslane

© 2022 - 2024 — McMap. All rights reserved.