Using Active Support Action Bar Enabled

I just changed our code to use the new SupportActionBar provided in the v7-appcompat library, but when I run the code on a Jellybean phone (apparently the same problem exists for Honeycomb and Ice Cream Sandwich), the home button has never been. seems activated.

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

If I replaced it with getActionBar (). setHomeButtonEnabled (true) works.

The theme 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> 

The style of the v11 + action bar 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> 

Does anyone know why the home button is not activated if the version of Android that supports the action bar is correct.

=== UPDATE === I just looked at the source code of the appcompat library, and I noticed the following in ActionBarImplBase, which looks wrong:

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

Does this mean that the "Home" button will be enabled only if the Android version is less than ICS or if the power indicator is on? - which I do not want.

+8
android android-actionbar appcompat
source share
5 answers

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

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

Did you try to manually manipulate the button?

 @Override public boolean onOptionsItemSelected(int featureId, MenuItem item) { int itemId = item.getItemId(); if(itemId == android.R.id.home){ // Do stuff } return true; } 
+12
source share

This worked for me:

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_your_activity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // ... other stuff } @Override public boolean onSupportNavigateUp(){ finish(); // or call onBackPressed() return true; } 

The onSupportNavigateUp() method is called when you use the back button in the SupportActionBar .

+9
source share

Try using the Sherlock library for Android devices such as the Gingerbread song toolbar and are only supported with 3.0, so the sherlock lock library provides backward compatibility.

http://actionbarsherlock.com/ --- download the library here.

Then add these lines to your code.

 ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setIcon(android.R.color.transparent); actionBar.setDisplayUseLogoEnabled(false); 

This will help you add the rear home key to the action bar. It will also make your icon invisible if you do not want to show it. But if you want your application to be displayed at all events, just comment on this line below

actionBar.setIcon (android.R.color.transparent);

+1
source share

Now try this one. Because I was able to solve my own problem, although it was on Sherlock. From your styles above, I see that you made some tweaks for your themes. In my case, I made some settings for my Sherlock theme, and this was what gave me the problem from the side on Android 4.0 and higher, my theme failed. so I just added a code snippet that tells the android to use the default Sherlock theme when it runs on Android 4.0 and above. Therefore, I believe that this will work for you. you tell the android to use the default theme of the v7-appcompat library in the Android version, which does not work for you.

Code below:

 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { this.setTheme(R.style.Theme_Sherlock); } else { this.setTheme(R.style.Theme_Sherlock_Light_DarkActionBar); } 

In your case, edit the theme in the v7-appcompat library.

Please mark as an answer if it works for you. I believe that one could customize the theme from the code for the places if you use this.

+1
source share

You can add an ActionBar to your activity when working at API level 7 or higher by adding an ActionBarActivity class for your activity and setting the Theme.AppCompat theme theme or a similar theme.

0
source share

All Articles