android - Cannot resolve method getActivity() in a class extending FragmentActivity -
i have extended fragment activity in class need have custom toolbar. so,i added code toolbar setsupportactionbar(toolbar) did not work.then, added appcompatactivity.getactivity() cast did not work well.
here code -
public class main_fragment extends fragmentactivity implements fragmentdrawer.fragmentdrawerlistener { private toolbar toolbar; private fragmentdrawer drawerfragment; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main_fragment); toolbar = (toolbar) findviewbyid(r.id.tool_bar); ((appcompatactivity) getactivity()).setsupportactionbar(toolbar); ((appcompatactivity) getactivity()).getsupportactionbar().setdisplayshowhomeenabled(true); drawerfragment = (fragmentdrawer) getsupportfragmentmanager().findfragmentbyid(r.id.fragment_navigation_drawer); drawerfragment.setup(r.id.fragment_navigation_drawer, (drawerlayout) findviewbyid(r.id.drawer_layout), toolbar); drawerfragment.setdrawerlistener(this); }
appcompatactivity
extends fragmentactivity
. first thing have change
extends fragmentactivity
with
extends appcompatactivity
getactivity()
method of fragment
. activity
has not method, don't need call use setsupportactionbar
, getsupportactionbar
setsupportactionbar(toolbar); getsupportactionbar().setdisplayshowhomeenabled(true);
Comments
Post a Comment