如何在片段中设置库

时间:2016-04-26 12:24:55

标签: android android-fragments android-studio navigation-drawer

我试图在片段(导航抽屉)中显示页面库。我成功完全能够为主要活动设置它现在我试图在导航抽屉中设置它这里是我的片段代码

  @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_navigation, container, false);
    Element versionElement = new Element();
    versionElement.setTitle("Version 6.2");

    Element adsElement = new Element();
    adsElement.setTitle("Advertise with us");

    View aboutPage = new AboutPage(Navigation.this)
            .isRTL(false)
            .addItem(versionElement)
            .addItem(adsElement)
            .addGroup("Connect with us")
            .addEmail("elmehdi.sakout@gmail.com")
            .addFacebook("the.medy")
            .addTwitter("medyo80")
            .addYoutube("UCdPQtdWIsg7_pi4mrRu46vA")
            .addPlayStore("com.ideashower.readitlater.pro")
            .addInstagram("medyo80")
            .addGitHub("medyo")
            .create();

    setContentView(aboutPage);
}

我使用的支持库How to set the about page library in android studio

1 个答案:

答案 0 :(得分:2)

我认为库构造函数采用 context 参数,并且您以错误的方式执行此操作。只需替换这一行:

View aboutPage = new AboutPage(Navigation.this)

用这个:

View aboutPage = new AboutPage(getActivity())

修改 在一天结束时,您无法从片段调用setContentView,其他解决方案是返回aboutPage视图,如此thraed建议,或者提到@ cricket_007,以使用FragmentManager将片段添加到特定的Activity。 / p>

设置ContentView how to set setContentView in fragment