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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -