getActionBar() returns Null (AppCompat-v7 21)

You need to call getSupportActionBar() on an ActionBarActivity. Do not call getActionBar() -- that is not available on older devices, and for the new r21 edition of appcompat-v7, I would expect it to return null all the time, as the new ActionBarActivity disables and replaces the system action bar.


If your activity is AppCompatActivity, you can get the action bar like this:

android.support.v7.app.ActionBar mActionBar = getSupportActionBar();

Object actionBar = getSupportActionBar();

android.support.v7.internal.app.WindowDecorActionBar bar = (android.support.v7.internal.app.WindowDecorActionBar) actionBar;

If you are developing app targeting 21SDK but app is going to be used under older sdk's then this lines above are the solution.

You can't use getActionBar() under 21SDK when your activity extends ActionBarActivity