java - Android 4.0/ICS - 操作栏上的应用程序图标不可点击

标签 java android android-actionbar android-4.0-ice-cream-sandwich xoom

出于某种原因,在我的 Motorola Xoom with Ice Cream Sandwich 上进行测试时,操作栏中的应用程序图标不可点击,即使我已经实现了事件处理程序。这只会在将 targetSdkVersion 更改为 15 后发生。如果它是 13,它仍然是可点击的,即使在 ICS 上也是如此。为什么会发生这种情况,我怎样才能让它像按钮一样可点击?我搜索了文档,但找不到任何内容。

谢谢。

更新:这是我的代码:

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(我的activity都是继承自这个类:

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

最佳答案

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

关于java - Android 4.0/ICS - 操作栏上的应用程序图标不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9050590/

相关文章:

java - 通过RabbitMQ维护correlationId

java - 不知何故,在递归过程中,对象在 list.add(object) 之后发生了变异。解释?

android - LoopJ AndroidAsyncHttp 和持久性 cookie 存储

android - 反序列化包含数组的 Firestore 文档的推荐方法是什么?

flutter - 如何在操作栏上有两个搜索栏?

android - 我的操作栏标题使用了错误的主题颜色

java - 如何解决这个无限 while 循环?

Java Calendar对象,分别设置日期和时间

android - 显示 map 时应用程序强制关闭

Android 爱彼迎之类的 Tabs