android - getActionBar returning null -


this question has answer here:

i have activity

and have added

 setsupportactionbar(toolbar); 

and want display home button on action bar. home button android predefined.

and calling method

getactionbar().setdisplayhomeasupenabled(true); 

but when run app, gives getactionbar retured null

full code of activity following

 @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);      setsupportactionbar(toolbar);       floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab);     fab.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             snackbar.make(view, "replace own action", snackbar.length_long)                     . setaction("action", null).show();         }     });        getactionbar().setdisplayhomeasupenabled(true); 

why getactionbar returning null? thats question.

you should try getsupportactionbar()


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -