Search code examples
androidandroid-4.0-ice-cream-sandwichandroid-actionbar

Use ActionBar without Activity


Is it possible to use ActionBar without activity? I want to use it in the StatusBar view, instead of view highlighted with purple color.

enter image description here


Solution

  • This screen shot, based on an image from the Android ui pages, labels the different components, just to make sure we're talking about the same thing.

    enter image description here

    You can't add an ActionBar outside of an Activity. You need an Activity to get an ActionBar reference. ActionBar references are retrieved via the Activity API, by calling the getActionBar() method inside the Activity.

    So you can't use an ActionBar to replace the StatusBar. You can change the StatusBar's color, and possibly layout, but only on a rooted phone. See this forum discussion for some perspective on the issue.

    AFAIK, there is no API for changing the Notification Drawer's layout and functionality. There are no API methods that allows us to place an ActionBar inside the drawer outside of the notifications e.g. at the top of the drawer like in your screenshot.

    You can create custom layouts for notifications(the messages inside the drawer). The Android Developer pages have an example on how to do it (see "Creating a Custom Notification Layout" at the bottom of the page). Again, you can't use an ActionBar but you can add Views to a Notification layout.