Use ActionBar without Activity - android

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

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.
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.

Use notifications. You will see something in the status bar and no Activity will be involved.

There's GOT to be a way to change the ActionBar from a class declared within an Activity:
(1) create method in activity to .setTitle
(2) pass activity context to Controller class (MVC) declared in Activity
(3) have Controller class call activity method to modify actionBar
...what do you think?

You should make a custom rom to change that view.
That Purple View is not part of your application but a part of Android.
If you do not want an Activity, why not make it transparent.
How do I create a transparent Activity on Android?

Related

What is the purpose of setSupportActionBar? What does it do?

If there is a toolbar, it is usually passed into setSupportActionBar(). Why?
As per docs
A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. An application may choose to designate a Toolbar as the action bar for an Activity using the setActionBar() method.
But in simple ways, this is a way of telling the Activity that you are interested in using the features related to Toolbar. It will delegate the functionalities related to your defined toolbar. It helps activity to understand the many of the requirements some of them mentioned below.
1) Setting menu options
2) Setting Navigation drawer
3) Setting common Toolbar
4) Setting back button on the top left
5) Using an icon for brand identification
6) Setting a common title or subtitle
7) And many more
If you don't mention for these functionalities by telling the activity using setSupportActionBar then you have to create all this by your self and support them back to the older version. With Toolbar it comes free and you have to just tell a activity to use it will take of supporting different functionalities itself.
if you want to apply your custom toolbar instead of default toolbar then to set toolbar into that specific screen/activity you must be use setSupportActionBar() along with your toolbar. ;)

Make Android Custom App Bar as Default in every Activity

I want to make android custom app bar that contains searchbox, icon, etc.
The solution on google that I found was changing the style to no action bar. And create a toolbar layout that need to be included in every activity I made.
I just wondering, can I make custom App bar that default appear in every activity without including them when creating Activity?
I would recommend using v7.widget.toolbar. At first you need to create custom layout for your toolbar. Then you need to set it as a support action bar in each activity that you want it to appear. Toolbar on every activity can contains different icons.
https://developer.android.com/training/appbar/setting-up.html

Changing Actionbar Background programmatically in one activity, changes in whole application

my problem is simple, it is relative to only Lollipop 5.0
I have a main activity where I set a certain theme then I set programmatically a custom background to the actionbar:
context.getActionBar().setBackgroundDrawable(context.getResources().getDrawable(
getCustomColor(context, Theme)));
Then I open another activity, where I set my custom theme, and my custom background drawable, this time made traslucent:
mActionBarBackgroundDrawable.setAlpha(0);
context.getActionBar().setBackgroundDrawable(
mActionBarBackgroundDrawable);
When I press back, if finishes the activity correctly but then my main activity has the actionbar completely transparent!
It is as if changing the background of the actionbar in my 2nd activity, changes it also to the 1st one!
It works correctly from android 4.0 to 4.4.4
Can you help me?
Thanks and regards
What is your context here? If it is pointing to the Application, it might do so. Try directly using
getActionBar().setBackgroundDrawable(mActionBarBackgroundDrawable);
in your Activity or if you are calling from Fragment
getActivity()getActionBar().setBackgroundDrawable(mActionBarBackgroundDrawable);

Multiple actionbar (one per fragment) in activity

Is it possible to add an action-bar to a fragment instead of an activity.
What I am trying to create is a master-detail application with left side dedicated to the master fragment and the right side to the detail fragment. I want to add a dedicated actionbar for each of those fragment.
Does actionbarsherlock/appcompat support this feature or I would need to create a custom actionbar? / Is there a library which allows you place actionbar like thing within a linear-layout?
ActionBar is a feature of Activity. You can only control it state from fragment, but not to create. So you should implement it yourself.
Is there a library which allows you place actionbar like thing within
a linear-layout?
I don't know, but you can use <include layout="#layout/custom_action_bar"> for ActionBar placing.

Setting Navigation Icon on Android ActionBar

So I'm working on adding ActionBarSherlock and the Navigation Drawer to a project that previously implemented a custom (very poorly written) "action bar". Instead of using fragments and a backstack of activities for navigation, some activities show and hide different layouts. (That is, suppose I am in a list mode and then select a button to go into an edit screen. The app currently hides the list layout and shows another layout.).
So I've added actionbar sherlock and a navigation drawer to all the activities. I want to be able to programmatically switch the navigation icon from the 3 lines to the arrow when certain buttons are pressed.
I can't figure out how to do this though. Any ideas?
Thanks!
The solution to this problem is to use the method:
setDrawerIndicatorEnabled(boolean enable)
inside the ActionBarDrawerToggle class.
After:
drawer.setDrawerListener(toggle);
Use this code:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.select);
It depends how wedded you are to built-in actionbar artifacts. You can always redraw the current actionbar by inflating a layout of your choosing, then calling
getSherlockActivity().getSupportActionBar().setDisplayShowTitleEnabled(false);
getSherlockActivity().getSupportActionBar().setDisplayShowHomeEnabled(false);
getSherlockActivity().getSupportActionBar().setDisplayShowCustomEnabled(true);
// Inflate and do whatever you need to your view...
getSherlockActivity().getSupportActionBar().setCustomView(abView);
getSherlockActivity().getSupportActionBar().show();
When you want to go back to your standard (assuming you're using a DrawerLayout to do your navigation drawer), you can just set make a call to setDisplayShowCustomEnabled(false) (re-enable showHome and showTitle as you please).
As far as I know, customization of the back button can only be done via themes. Besides, swapping the drawer icon for the back icon (within the same Activity) doesn't make sense, since users would still be able to access the navigation drawer by sliding the left most edge to the right. It just wouldn't make sense.
If you absolutely need the back icon, then it would make the most sense to make that screen a new Activity since you would indeed be adding another "level" to the stack, which is what the back icon represents.

Categories

Resources