AppIntro Android库。我如何使用其xml和.java片段?

时间:2015-10-09 20:42:28

标签: android

AppIntro是一款Android库,可帮助您为自己的应用制作精彩的介绍。

AppIntro Library

    // Add your slide's fragments here
    // AppIntro will automatically generate the dots indicator and buttons.
    addSlide(first_fragment);
    addSlide(second_fragment);
    addSlide(third_fragment);
    addSlide(fourth_fragment);

但是当我尝试附加由我创建的片段时,我收到错误。

enter image description here

这就是错误:

enter image description here

如何添加我的fragment1?

3 个答案:

答案 0 :(得分:2)

虽然addSlide()方法需要android.supportv4.app.Fragment作为参数,但您的自定义Fragment1应该从android.supportv4.app.Fragment类扩展。

答案 1 :(得分:0)

1,

import android.support.v4.app.Fragment;

2,

public class Slide_First extends  Fragment {
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.slide_first, null);
        return view;
    }


}

答案 2 :(得分:0)

首先:像往常一样创建片段,并向其中添加所需的xml元素,然后在您的活动中执行此操作

编辑:没有必要扩展到AppIntro或AppIntro2

public class MyIntro extends AppIntro2 implements ISlidePolicy {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);

        Intro1 fragment1 = new Intro1 ();
        Intro2 fragment2 = new Intro2 ();
        Intro3 fragment3 = new Intro3 ();
        addSlide (fragment1);
        addSlide (fragment2);
        addSlide (fragment3);

//Only personalization
        showStatusBar (false);
        showSkipButton (false);
        setFadeAnimation ();
        setBarColor (Color.TRANSPARENT);

    }
}

Edit2:将这些依赖项导入您的片段中

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;