ProgressBar inside ActionBar from fragment - android

I tried the following method but it does not work.
getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getActivity().setProgressBarIndeterminateVisibility(false);

First, make sure your
getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
Is before your
setContentView(R.layout.activity_layout);
Then call
getActionBar();
Before you use your
getActivity().setProgressBarIndeterminateVisibility(false);
How this works, is you are adding the window feature before your view is drawn. Then the getSupportActionBar() is used to just "open" the connection with your actionbar methods.

Related

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.

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");

android: title bar hide

I have this activity made with actionBarSherlock. Is it possible to hide title of activity (not only text but the title bar) I tried:
getSupportActionBar().hide();
but it hides tabs too.
Picture:
https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-prn1/q71/1017267_10200157522600680_915484448_n.jpg
1.You must call setNavigationMode(NAVIGATION_MODE_TABS) to make the tabs visible
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
2.You must disable the activity title by calling setDisplayShowTitleEnabled(false)
getSupportActionBar().setDisplayShowTitleEnabled(false);
3.You must disable application home affordance by calling setDisplayShowHomeEnabled(false)
getSupportActionBar().setDisplayShowHomeEnabled(false);
This way should able to able to get a look like this in your activity.
try one of these possibly?
add this to the manifest file under application:
android:theme="#android:style/Theme.NoTitleBar"
or in your activity:
ActionBar actionBar = getActionBar();
actionBar.hide();
getActionBar().setDisplayOptions(Window.FEATURE_NO_TITLE);
It worked for me hope it will help you out.
And this will give result like this

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