Change ActionBar overlay from Fragment - android

I am using ActionBar Compat with NavigationDrawer from this source NavigationDrawer using only Android Support Library
I have a NavigationDrawer with some items, each item is a Fragment. Is it possible to change ActionBar overlay mode from Fragment to Fragment? I´d like to make ActionBar transparent in grid view, but keep it opaque in other case. How do I set this from Fragment?

in your fragment call, getActivity() and cast to ActionBarActivity with a getSupportActionBar()
// Update activity title
ActionBar actionBar = ((ActionBarActivity) getActivity()).getSupportActionBar();
actionBar.setTitle("lorem ipsum");
For making it transparent, have a look at this blog post:
http://flavienlaurent.com/blog/2013/11/20/making-your-action-bar-not-boring/

Related

ActionBar with SearchView and tabs

I need to show the following ActionBar:
Does Android support it, or do I need to do a custom layout and set it to the ActionBar?

Is getActionBar() supposed to return null?

I'm trying to make a Toolbar in a fragment an Action Bar. This is what I do:
View view = inflater.inflate(R.layout.fragment_sourceitem_list, viewGroup, false);
android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) view.findViewById(R.id.toolbar);
((AppCompatActivity) mListener).setSupportActionBar(toolbar);
where mListener is the Activity that contains the fragment.
However, if I have the following straight after
ActionBar actionbar = ((AppCompatActivity) mListener).getActionBar();
actionbar is null. How come it's still null even when the ActionBar has been set in the previous line already? Otherwise, what's a good way to set the property of the newly set ActionBar?
Thanks
Since you use AppCompatActivity you use the supportActionBar and therefor you need to use getSupportActionBar().
This supports older android versions than the normal Activity and ActionBar.

Clear actionbar in fragments

I have couple of fragments with NavigationDrawer. One of the fragment's actionbar has Spinner and others have just the title.
Now when I open the fragment which has spinner in actionbar and then click on the navigation drawer to open the another fragment class. The actionbar has the spinner and then title.
How do I clear the actionbar just to show the title and not the spinner? I mean clear the actionbar and show what is required.
Let me know!
When you switch to Second fragment(which has only title to display), in it's onStart() method, you can disable/hide the Spinner, using below code:
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
You then need to add code in your first fragment to show Spinner again!
I think invoking invalidateOptionsMenu() should work. You should invoke this method when opening your second fragment.

Tabs go to top if i set customView of ActionBar on Android

I add tabs and viewpager to my project.
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Everything is perfect until i set custom view of actionBar:
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
....
actionBar.setCustomView(vv,layoutParams);
Perfect: ActionBar itself at the top and tabs are below the actionBar.
When i set the custom view, tabs change place and goes to top and actionBar goes to below of tabs.
What am i doing wrong? I want the actionbar stay always at the top of the screen.
You can vote for this bug on Android code:
https://code.google.com/p/android/issues/detail?id=36191
There are some tricks to avoid this that you can read here: https://github.com/JakeWharton/ActionBarSherlock/issues/327
But the official Google answer is
This is a working as intended UX decision.
(Roman Nurik).

Adding headers and footer in actionbar tabs

Hi everyone I am working currently a view which need to have a view above the tabs of the actionbar or more like below the action bar itself, and a fixed footer between the tabs.
But I have not find a way to make this behaviour other than adding the footer in each fragment and the view that I want below the tabs.
Is there a way to put headers(above) and footer(below) tabs using the actionbar?
PD. I am using Sherlock actionbar
Something inbetween the Actionbar and the Actionbar tabs? AFAIK it's not possible. ABS is only used in pre HC versions. On ICS+ the default ActionBar gets used. Therefore even if you can customize the ABS Actionbar you most likely can't override the default Actionbar on ICS+.

Categories

Resources