android - getSupportActionBar from inside of Fragment ActionBarCompat -
i'm starting new project uses appcompat/actionbarcompat
in v7
support library. i'm trying figure out how use getsupportactionbar
within fragment. activity hosts fragment extends actionbaractivity
, don't see similar support class fragments.
from within fragment
public class crimefragment extends fragment { //... getactivity().getsupportactionbar().setsubtitle(r.string.subtitle); // getsupportactionbar not defined in v4 version of fragment //... }
the google page using (http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html) says there should no changes v4
fragment. need cast getactivity()
calls actionbaractivity
? seems poor design.
after fragment.onactivitycreated(...) you'll have valid activity accessible through getactivity(). you'll need cast actionbaractivity make call getsupportactionbar().
((appcompatactivity)getactivity()).getsupportactionbar().setsubtitle(r.string.subtitle);
you need cast. it's not poor design it's backwards compatibility.
Comments
Post a Comment