使用支持行动起来吧家里启用来吧、家里、行动

2023-09-12 21:54:15 作者:SOBER.

我刚刚修改了我们的code使用的V7-appcompat库提供的新SupportActionBar但在一个杰利贝恩手机上运行的code时(presumably存在蜂窝和冰一样的问题冰淇淋三明治)的home键没有以往似乎并没有被激活。

I've just modified our code to use the new SupportActionBar provided in the v7-appcompat library but when running the code on a Jellybean phone (presumably the same problem exists for Honeycomb and Ice Cream Sandwich) the home button doesn't ever seem to be activated.

调用getSupportActionBar()setHomeButtonEnabled(真)。似乎并没有做什么,它说,但适用于姜饼手机。

Calling getSupportActionBar().setHomeButtonEnabled(true); doesn't seem to do what it says but works for Gingerbread phones.

如果我有getActionBar()代替它。setHomeButtonEnabled(真),它的工作。

If I replace it with getActionBar().setHomeButtonEnabled(true) it does work.

这是我使用的V11 +的主题如下:

The theme that I use for v11+ is as follows:

<style name="MyTheme" parent="@style/Theme.AppCompat">
    <item name="android:windowActionBar">true</item>
    <item name="android:windowNoTitle">false</item>
    <item name="android:listViewStyle">@style/MyListView</item>
    <item name="android:actionBarStyle">@style/MyActionBarStyle</item>
    <item name="android:windowSoftInputMode">stateAlwaysHidden</item>
    <item name="android:buttonStyle">@style/MyButton</item>
    <item name="android:radioButtonStyle">@style/MyRadioButtonStyle</item>
    <item name="android:windowContentOverlay">@drawable/ab_solid_dove_grey</item>
    <item name="android:windowTitleSize">@dimen/action_bar_height</item>
    <item name="android:selectableItemBackground">@drawable/sel_standard_item</item>
    <item name="android:windowBackground">@drawable/default_bg</item>
    <item name="android:actionMenuTextAppearance">@style/MyActionBarText</item>
    <item name="android:actionMenuTextColor">@color/gallery</item>
    <item name="android:tabWidgetStyle">@style/MyTabWidget</item>
</style>

和动作栏样式V11 +的定义:

And the action bar style v11+ is defined:

<style name="MyActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
    <item name="android:displayOptions">useLogo|showHome|showCustom</item>
    <item name="displayOptions">useLogo|showHome|showCustom</item>
    <item name="android:actionBarSize">@dimen/action_bar_height</item>
    <item name="android:icon">@drawable/ic_launcher</item>
    <item name="android:background">@android:color/transparent</item> <!-- Remove blue line from bottom of action bar -->
</style>

任何人都知道为什么没有得到上正确支持操作栏的Andr​​oid版本启用了home键的时候。

Anyone know why the home button is not getting enabled when on an Android version that supports action bar correctly.

===更新=== 我只是看着源$ C ​​$ C为appcompat图书馆,我注意到ActionBarImplBase看起来我错了以下内容:

=== UPDATE === I've just looked at the source code for the appcompat library and I've noticed the following in ActionBarImplBase which looks wrong to me:

 setHomeButtonEnabled(abp.enableHomeButtonByDefault() || homeAsUp);

这意味着如果Android版本低于ICS或如果我启用了指示灯的home键才会启用? - 这是我不希望

This means that the home button will only be enabled if the Android version is less than ICS or if I've enabled the up indicator? - which I don't want.

推荐答案

您是否尝试过使用所有这三个(也尝试对换getSupportActionbar)?

Have you tried using all three of these (also try swapping for getSupportActionbar)?

 getActionBar().setDisplayShowHomeEnabled(true);
 getActionBar().setHomeButtonEnabled(true);
 getActionBar().setDisplayHomeAsUpEnabled(true); 

编辑:您是否尝试过手动操作按钮

Have you tried handling the button manually?

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {

     int itemId = item.getItemId();

     if(itemId == android.R.id.home){
         // Do stuff
     }
     return true;
}

编辑2:对不起,我给你的错误的方法

Edit 2: Sorry, I gave you the wrong method.

@Override
public boolean onOptionsItemSelected(int featureId, MenuItem item) {

     int itemId = item.getItemId();

     if(itemId == android.R.id.home){
         // Do stuff
     }
     return true;
}