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

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -