getSupportActionBar from inside of Fragment ActionBarCompat

问题:

I'm starting a new project that uses the AppCompat/ActionBarCompat in v7 support library. 我正在启动一个在v7支持库中使用AppCompat/ActionBarCompat的新项目。 I'm trying to figure out how to use the getSupportActionBar from within a fragment. 我试图弄清楚如何在片段中使用getSupportActionBar My activity that hosts the fragment extends ActionBarActivity , but I don't see a similar support class for Fragments. 我托管片段的活动扩展了ActionBarActivity ,但我没有看到类似Fragment的支持类。

From within my fragment 从我的片段中

    public class CrimeFragment extends Fragment {
          //...

          getActivity().getSupportActionBar().setSubtitle(R.string.subtitle); // getSupportActionBar is not defined in the v4 version of Fragment

          //...
    }

The google page for using it ( http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html ) says there should be no changes for the v4 fragment. 使用它的谷歌页面( http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html )表示v4片段应该没有变化。 Do I need to cast all my getActivity() calls to an ActionBarActivity ? 我是否需要将所有getActivity()调用getActivity()转换为ActionBarActivity That seems like poor design. 这似乎是糟糕的设计。


解决方案:

参考: https://stackoom.com/en/question/1Es3N
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章