Clear actionbar in fragments - android

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.

Related

Android - invisible ActionBar with back button

I know how to implment ActionBar with back button. But I want to make ActionBar invisible or with no background, I want to have only visible back button arrow. Is it possible?
With a little of search you will find the response. Any way you can try this :
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
If you want to have your tab background below your ActionBar add this too :
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));

Fragment with actionbar

When I add a fragment to my xml file, it shows all the content but not the fragment's action bar. How can I change the default behaviour to show the actionbar too?
From the Fragment, in your onCreate() method, you can try calling
getActivity().getActionBar().show();
you can set the title by using
getActivity().getActionBar().setTitle("title");

How to show the title in Fragment but hide in the Activity?

I have a Activity and it has include more than one fragment.
I know it can use requestWindowFeature(Window.FEATURE_NO_TITLE); to hide the title in Activity.
But I don't want to hide title for all fragment.
Can I hide the title for preference fragment ?
Based on what you say, you will have to use more than one activity. For the fragments that are in a same activity, the title bar is either shown or hidden.
Do not use requestWindowFeature(Window.FEATURE_NO_TITLE); We can get actionBar and hide it after setContentView
When active fragment, show action bar
When fragment detach , notify activity and activity can hide the action bar
Above is my current implement and seems work. Still testing :-D
Simple sample here - https://bitbucket.org/jimmy64/fragmentsample

Change ActionBar overlay from Fragment

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/

Hide Home button on ActionBar Sherlock Actionbar extending Navigation Activity

I am using ActionBarSherlock on my simple app and would like to hide the HOME button if the user is on the home/main activity. I understand how to do so with the setHomeButtonEnabled(false), however, I am extending a class that contains my navigation and has setHomeButtonEnabled(true) and I cannot seem to overwrite that setting in my main activity.
Thanks to #andy I am able to get rid of the icon, however, I cannot get rid of the < arrow. Any ideas?
Thanks for any help.
With ActionBarSherlock just put this in your home/main activity onCreate() method:
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
The only way I have found to do this is to not have this set on your baseActivity:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
and then set it as you will for each activity that requires the menu:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
or
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
Get the home button view and apply this
mHomeButton.setVisibility(View.INVISIBLE);

Categories

Resources