As far as I know, you need to set the Activity (to which the Fragment attached) for the ActionBar :
ActionBar actionBar = getActivity().getActionBar();
Or, if you use the support library and / or ActionBarSherlock:
ActionBar actionBar = getFragmentActivity().getSupportActionBar();
Fragments do not define the getActionBar() method, therefore an error message.
source share