出于某种原因,在我的 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/