android studio中的appintro中的addSlide方法出错

时间:2017-02-22 14:59:48

标签: 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.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);
    }

}

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

2 个答案:

答案 0 :(得分:0)

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

http://www.androidhive.info/2016/05/android-build-intro-slider-app/

答案 1 :(得分:0)

AppIntroSample 文件中的以下导入AppIntro库效果最佳:

coding

而不是:

import android.support.v4.app.Fragment;