简体   繁体   English

Android 4.0 / ICS - 操作栏上的应用程序图标无法点击

[英]Android 4.0 / ICS - App Icon on Action Bar not clickable

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. 出于某种原因,在使用Ice Cream Sandwich在我的Motorola Xoom上进行测试时,即使我已经实现了事件处理程序,操作栏中的应用程序图标也不可点击。 This only occurs after changing the targetSdkVersion to 15. If it is 13 it is still clickable, even on ICS. 这仅在将targetSdkVersion更改为15后才会发生。如果它是13,它仍然是可点击的,即使在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: 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: BaseActivity.java(我的活动都继承自这个类:

...
@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);
    }
}
...

I found it in the documentation at http://developer.android.com/guide/topics/ui/actionbar.html : 我在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). 注意:如果您使用该图标导航到主页活动,请注意从Android 4.0(API级别14)开始,您必须通过调用setHomeButtonEnabled(true)显式启用该图标作为操作项(在以前的版本中,默认情况下,图标已启用为操作项)。

Would you like to use the following code: 您要使用以下代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM