0

I have a problem with ActionBar.

I set minsdk in AndroidManifest to 14. Next I create Activity (BlankActivity), thats create MyACtivity class which extend ActionBarActivity and import android.support.v7.app.ActionBarActivity. I think that this library need only if you use sdk level 7 or lower.

This import correctly? Or i need use another extend class?

And I try change extend class to Activity, but its does not create ActionBar on Activity.

How add ActionBar on this Activity?

P.S. I was misled, because on my sdk function getActionBar must work, its NullPointer, because my app use this strange import. A can use getSupportActionBar, but its strange use support library for sdk 7 to create Application for sdk 14 or higher.

P.S.S. Thanks!! If anybody have same problen, there is some links about toolbar:

http://www.101apps.co.za/index.php/articles/using-toolbars-in-your-apps.html

Why was ActionBarActivity deprecated

Community
  • 1
  • 1
Ilja Bulatov
  • 63
  • 1
  • 9

3 Answers3

0

It's better you start with a working example. Just check in you android sdk installation for the folder \samples\android-21\ui\ActionBarCompat-Basic.

xcesco
  • 4,690
  • 4
  • 34
  • 65
0

The use of the support library is correct, just follow the ActionBar Developer guide here.

Mikel
  • 1,581
  • 17
  • 35
0

I have a problem with ActionBar.

Who doesn't ;)

I think that this library need only if you use sdk level 7 or lower.

The appcompat-v7 library used to backport API 14 Action Bar to platforms below that. APIs 7 through 13 used this reimplementation, APIs from 14 used native Action Bar.

Since Lollipop the appcompat-v7 always uses it's own implementation of Action Bar and backports Material theme from Lollipop.

This import correctly? Or i need use another extend class?

To have the Action Bar with appcompat-v7 your activity class must extend AppCompatActivity (previously ActionBarActivity) and it's theme must descend from Theme.AppCompat.* family.

And I try change extend class to Activity, but its does not create ActionBar on Activity.

Native activities on Lollipop don't have any Action Bar by default. You would supply it by having a Toolbar widget in your layout and calling setActionBar(Toolbar). Similar approach can also be used with appcompat-v7 (if you use a theme without default action bar) by calling setSupportActionBar(Toolbar).

How add ActionBar on this Activity?

[...] but its strange use support library for sdk 7 to create Application for sdk 14 or higher.

It's perfectly OK, the goal is to make the app look the same from API 7 to API 22. Appcompat-v7 now backports not only the Action Bar but Material theme as well.

Community
  • 1
  • 1
Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124