Here is my code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
//android.support.v7.app.ActionBar actionBar = getSupportActionBar();
If you are extending AppCompatActivity
then you are providing backward support for older Android versions and for that you have to use getSupportActionBar()
.
If you are importing android.app.ActionBar
then you have to use getActionBar()
and if you are importing android.support.v7.app.ActionBar
then you have to use getSupportActionBar()
.
Note: By using android.support.v7.app.ActionBar
, you can provide backward support for older Android versions.
If you are using AppCompat you always have to call getSupportActionBar()
no matter which Android Version your App is running.
Which Android versions do you target?
I would advise you to use the new Toolbar instead of ActionBar, because it's way more flexible to use.