Action bar Back button not working

I solved these problem by adding the below coding in GalleryActivity. ActionBar actionBar; actionBar=getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; } return super.onOptionsItemSelected(item); } In MainActivity: Previously, public class HomeActivity extends BaseActivity Then I change into public class HomeActivity extends FragmentActivity In GalleryFragment: I use Intent … Read more

remove padding around action bar left icon on Android 4.0+

Digging into AOSP sources, it seems the code involved is in com.android.internal.widget.ActionBarView.java. In particular the relevant part is the onLayout() method of the inner class ActionBarView$HomeView, partially reported below (lines 1433-1478): @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { … final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); final int iconHeight … Read more

NullPointerException: with ActionBar.setDisplayHomeAsUpEnabled(boolean)’ on a null object reference

The cause of your issue is using MainActivity extend Activity with support theme style name=”AppTheme” parent=”Theme.AppCompat.Light.DarkActionBar”. It’s incompatible things. Which min sdk you need? In your code having MainActivity extends Activity you don’t need AppCompatTheme. Use name=”AppTheme” parent=”android:Theme.Light“ If you are using Theme.AppCompat.Light.DarkActionBar, you should extend your Activity from AppCompatActivity, and use getSupportActionBar(). Instead of: … Read more

How to slide the ActionBar along with the NavigationDrawer

PLEASE NOTE: This answer was originally written when Android 4.4 (KitKat) was still pretty new. Since Android 5.0 and especially because of the introduction of the ToolBar this answer cannot be considered up-to-date anymore! But from a technical perspective and for those of you who want to learn about the inner workings of Android this … Read more

Exception: This is not supported, use MenuItemCompat.getActionProvider()

First, you cannot use android.widget.ShareActionProvider with the appcompat-v7 action bar backport (e.g., ActionBarActivity). Either use the appcompat-v7 version of ShareActionProvider, or move everything over to the native action bar. Second, if you stick with appcompat-v7, then you cannot safely use getActionProvider(), as that method will not exist on API Level 10 and below. Replace menuItem.getActionProvider() … Read more

How do I get a copy of the Android overflow menu icon? [closed]

Can somebody please provide a link to download the overflow menu icon? http://developer.android.com Once you have downloaded the SDK, you will find your images in: $ANDROID_SDK/platforms/$PLATFORM/data/res/$DRAWABLE/ic_menu_moreoverflow* where: $ANDROID_SDK is wherever you installed your SDK $PLATFORM is some platform directory (e.g., android-17) $DRAWABLE is some major drawable directory (e.g., drawable-hdpi) There are different versions of the … Read more

Getting DrawerLayout to Slide over the ActionBar

you can use below libraries to get navigation model similar to Google play music app. ActionBarSherlock (github) nested-fragments (github) PagerSlidingTabStrip (github) NavigationDrawer (Android developer site) Latest Support v4 library I have created a project Navigation Drawer with Tab Strip Example at github, have a look at it. Below is the screenshot of it.

Custom view for Menu Item

What you need to do is create a layout file with the view that you want for the item, the when you declare the item on the menu, assign the layout like this: <item android:id=”@+id/menu_pick_color” android:title=”@string/pick_color” app:showAsAction=”always” app:actionLayout=”@layout/my_custom_item”/> And that’s it! EDIT: To access the custom item and modify it’s color at runtime you can … Read more