Calling getActionBar
returns null
. This has been frequently reported so I've made sure to include the solutions others have used: My minSdkVersion=11
, I do have a titlebar, and I'm calling getActionBar
after setContentView
. Also, my activity is not a child activity.
setContentView(R.layout.main);
// experiment with the ActionBar
ActionBar actionBar = getActionBar();
actionBar.hide();
Device is a Samsung Galaxy Tab 10.1 running Android 3.2
Thanks in advance for any ideas or suggestions!
If you create an application project for API14 or above, there will be a values-14 folder. Make sure that folder exists and it has a styles.xml file with:
I got this error because I created a new project and I didn't want any extra values folders in my project, so I just kept the values folder and removed the values-v11 and values-v14 folders. But apparently the default theme for API14 and above requires an ActionBar in it's parent XML tag if you want to use the ActionBar. So I assumed I could do that incorrectly! Hope this helps somebody. Your most likely to resolve your issues with the above answers though.
Action bar needs theme or activity with app title to be there. Make sure you have not styled your application or activity as Theme.NOTITLE.
I was trying to get the ActionBar from within a fragment inside an ActionBarActivity using the support library. I had to do this:
My next quest is to figure out how to make this generic. For example, this code feels dirty because it requires my Fragment to know both that it's being used by an ActionBarActivity and using the support library. I think it should be a method that checks
getActivity().getActionBar()
first followed by the code above catching the ClassCastException if the parent Activity is not an ActionBarActivity.It seems you need to request having an Actionbar (!= titlebar) either via a Theme or via below code.
Code from [here]
Change the order of system request:
It seems there are several conditions which need to be met in order for this to work. The one which stumped me for a long time was this:
Make sure your activity extends Activity (NOT ActionBarActivity).
Make sure your app manifest has something like
and make sure your activity layout has
-Mark