Android ActionBar左上角的夏洛克图标不';不要向上航行

Android ActionBar左上角的夏洛克图标不';不要向上航行,android,android-actionbar,actionbarsherlock,Android,Android Actionbar,Actionbarsherlock,我正在使用ActionBarSherlock为Android蜂巢的前/后两个版本实现ActionBar。 我的问题是,当我在Android版本4.0.4上点击左上角的图标时,它没有响应。 以下是我迄今为止所做的: 1) 在所有样式文件夹“values/styles.xml”、“values-v11/styles.xml”和“values-v14/styles.xml”中;我已经做了以下工作 <style name="ActivityTheme" parent="@style/AppThem

我正在使用ActionBarSherlock为Android蜂巢的前/后两个版本实现ActionBar。 我的问题是,当我在Android版本4.0.4上点击左上角的图标时,它没有响应。 以下是我迄今为止所做的:

1) 在所有样式文件夹“values/styles.xml”、“values-v11/styles.xml”和“values-v14/styles.xml”中;我已经做了以下工作

<style name="ActivityTheme" parent="@style/AppTheme">
        <item name="actionBarStyle">@style/ActivityActionBarStyle</item>
        <item name="android:actionBarStyle">@style/ActivityActionBarStyle</item>
    </style>
<style name="ActivityActionBarStyle" parent="ommaralrd_transparent_ActionBar">
        <item name="displayOptions">showHome|showTitle|homeAsUp</item>
        <item name="android:displayOptions">showHome|showTitle|homeAsUp</item>
    </style>
<style name="ActivityTheme" parent="@style/AppTheme">
        <item name="actionBarStyle">@style/ActivityActionBarStyle</item>
        <item name="android:actionBarStyle">@style/ActivityActionBarStyle</item>
    </style>
<style name="ActivityActionBarStyle" parent="ommaralrd_transparent_ActionBar">
        <item name="displayOptions">showHome|showTitle</item>
        <item name="android:displayOptions">showHome|showTitle</item>
    </style>

@样式/活动ActionBarStyle
@样式/活动ActionBarStyle
showHome | showTitle | homeAsUp
showHome | showTitle | homeAsUp
在任何应用程序活动中(家庭活动除外,因为它不应具有向上箭头),我已完成以下操作:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inner);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
            getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        }
.....rest of my code ...
}


@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent intent;
        switch (item.getItemId()) {
        case android.R.id.home:

            /*app icon in action bar clicked; go home*/
            intent = new Intent(this, MainActivity.class);

            /* With this flag, if the activity you're starting already exists in the current task, 
             * then all activities on top of it are destroyed and it is brought to the front.
             * you should usually not create a new instance of the home activity. Otherwise, 
             * you might end up with a long stack of activities in the current task with multiple 
             * instances of the home activity.*/
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            break;
        default:
            return super.onOptionsItemSelected(item);
        }
        return true;
    }
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_-inner);
if(Build.VERSION.SDK\u INT
在清单文件中,我确保已将各自的样式应用于所有活动(主活动除外,因为它不应具有向上箭头)


所以现在,当我在Pre HoneyComb版本上测试应用程序时,向上箭头从未显示,这是正确的,因为如果点击图标向上导航,ABS根本无法响应。 但当我在Emulator上的Post HoneyComb版本(如4.1)上尝试该应用程序时,会显示向上箭头,当我点击它时,它会按预期工作并正常向上导航。 我的问题是,当我在Android 4.0.4 emulator上尝试该应用程序时,向上箭头如预期所示,但当我点击它时,它什么也不做

我找到了修复方法: 简单地说,我应该避免使用xml属性:homeAsUp将图标Home设置为Up,但我应该使用setDisplayHomeAsUpEnabled(true),如下所示:

在所有样式文件夹“values/styles.xml”、“values-v11/styles.xml”和“values-v14/styles.xml”中;我已经做了以下工作

<style name="ActivityTheme" parent="@style/AppTheme">
        <item name="actionBarStyle">@style/ActivityActionBarStyle</item>
        <item name="android:actionBarStyle">@style/ActivityActionBarStyle</item>
    </style>
<style name="ActivityActionBarStyle" parent="ommaralrd_transparent_ActionBar">
        <item name="displayOptions">showHome|showTitle|homeAsUp</item>
        <item name="android:displayOptions">showHome|showTitle|homeAsUp</item>
    </style>
<style name="ActivityTheme" parent="@style/AppTheme">
        <item name="actionBarStyle">@style/ActivityActionBarStyle</item>
        <item name="android:actionBarStyle">@style/ActivityActionBarStyle</item>
    </style>
<style name="ActivityActionBarStyle" parent="ommaralrd_transparent_ActionBar">
        <item name="displayOptions">showHome|showTitle</item>
        <item name="android:displayOptions">showHome|showTitle</item>
    </style>

相反,使用
getSupportActionBar().setDisplayHomeAsUpEnabled(true)允许在所有版本上单击主页,即使是2.2。你甚至可以看到箭头。@A--C你是对的,但我注意到,在使用Action Bar Sherlock时,Android 4.1的主页图标是可点击的,而Android 4.0的主页图标是不可点击的……你可以在4.1和4.0的两个不同模拟器中尝试,以重现我的问题我使用了最简单的方法,将主题设置为
Theme.Sherlock
并使用
setDisplayHomeAsUpEnabled(true)它在ICS(4.0.4)上正常工作,因此不幸的是,我无法重现您的问题。@A--C我想我找到了问题的解决方法。。。。为了准确地重现错误,请不要调用setDisplayHomeAsUpEnabled,而是在相应的styles.xml文件中使用homeAsUp。简单地说,我删除了homeAsUp并使用了显式API setDisplayHomeAsUpEnabled,它现在在Android 4.0和Android 4.1上都能正常工作