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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章