I have an activity that extends ActionBarActivity and hosts a single fragment shown here:
import android.support.v7.app.ActionBarActivity;
public class CrimePagerActivity extends ActionBarActivity{
When I try to make a call to
getSupportActionBar()
I get an error saying it cannot be resolved. I tried passing in
getActionBar()
which produced a NullPointerException error at runtime.
Here is the code in question.
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_crime, container, false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
if(NavUtils.getParentActivityName(getActivity()) != null) {
getActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
Resolved the issue by casting the return of getActivity()
to ActionBarActivity
:
((ActionBarActivity)getActivity()).getSupportActionBar()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With