11
votes

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);
    }
}
...
2
Tested on the emulator? Is it clickable there?Leandros
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).SZH
@Leandros Done. Has anyone else experienced this?SZH

2 Answers

25
votes

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).

0
votes

Would you like to use the following code:

ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);