android studio中appintro中的addSlide方法出错

android studio中appintro中的addSlide方法出错,android,Android,此行中有一个错误: addSlide(AppIntroSampleSlider.newInstance(R.layout.app_intro1)); addSlide (android.support.v4.app.Fragment) 在AppIntroBase中,无法应用它 我的代码在这里: import android.content.Intent; import android.os.Bundle; import android.widget.Toast; import com.git

此行中有一个错误:

addSlide(AppIntroSampleSlider.newInstance(R.layout.app_intro1));

addSlide (android.support.v4.app.Fragment)
在AppIntroBase中,无法应用它

我的代码在这里:

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.github.paolorotolo.appintro.AppIntro;

/**
 * Created by Arvind on 2/6/2017.
 */
public class MyIntro extends AppIntro {

    @Override
    public void init(Bundle savedInstanceState) {

        //adding the three slides for introduction app you can ad as many you needed
        addSlide(AppIntroSampleSlider.newInstance(R.layout.app_intro1));
        addSlide(AppIntroSampleSlider.newInstance(R.layout.app_intro2));
        addSlide(AppIntroSampleSlider.newInstance(R.layout.app_intro3));

        // Show and Hide Skip and Done buttons
        showStatusBar(false);
        showSkipButton(false);

        // Turn vibration on and set intensity
        // You will need to add VIBRATE permission in Manifest file
        setVibrate(true);
        setVibrateIntensity(30);

        //Add animation to the intro slider
        setDepthAnimation();
    }

    @Override
    public void onSkipPressed() {
        // Do something here when users click or tap on Skip button.
        Toast.makeText(getApplicationContext(),
                getString(R.string.app_intro_skip), Toast.LENGTH_SHORT).show();
        Intent i = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(i);
    }

    @Override
    public void onNextPressed() {
        // Do something here when users click or tap on Next button.
    }

    @Override
    public void onDonePressed() {
        // Do something here when users click or tap tap on Done button.
        finish();
    }

    @Override
    public void onSlideChanged() {
        // Do something here when slide is changed
    }
}
我创建了一个类,即AppIntroSampleSlider。 我的AppIntroSampleSlider类是:

package com.example.arvind.appintro1;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Arvind on 13-Feb-17.
 */

public class AppIntroSampleSlider extends Fragment {
    private static final String ARG_LAYOUT_RES_ID = "layoutResId";

    public static AppIntroSampleSlider newInstance(int layoutResId) {
        AppIntroSampleSlider sampleSlide = new AppIntroSampleSlider();

        Bundle bundleArgs = new Bundle();
        bundleArgs.putInt(ARG_LAYOUT_RES_ID, layoutResId);
        sampleSlide.setArguments(bundleArgs);

        return sampleSlide;
    }

    private int layoutResId;

    public AppIntroSampleSlider() {}

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

        if(getArguments() != null && getArguments().containsKey(ARG_LAYOUT_RES_ID))
            layoutResId = getArguments().getInt(ARG_LAYOUT_RES_ID);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(layoutResId, container, false);
    }

}

我想知道为什么它在代码中显示错误。所以请帮助我解决这个错误。

我找到了一个没有错误的更好示例


我找到了一个没有错误的更好的例子


AppIntro库在AppIntroSampleSlider.java文件中的以下导入最有效:

而不是:

import android.app.Fragment;

AppIntro库在AppIntroSampleSlider.java文件中进行以下导入时效果最佳:

而不是:

import android.app.Fragment;