Search code examples
android-fragmentsandroid-actionbaractionbarsherlock

How to use ActionBar features from a fragment?


In a fragment code I'd like to make ActionBar API calls such as

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

Is it a good idea to hold a reference to the activity in the fragment's code or is there a better way to approach this?

I'm using SherlockFragment for compatibility.


Solution

  • I just realized SherlockFragment has getActivity() and getSherlockActivity() methods, so I can write:

    this.getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    this.getSherlockActivity().setProgressBarIndeterminateVisibility(true);