登机滑块屏幕

时间:2018-11-29 17:05:43

标签: android slider screen splash-screen

我已经使用一个内置库来创建“ android内置滑板屏幕”。该库是实现'com.github.apl-devs:appintro:v4.2.3'。简介屏幕应仅在应用程序启动时第一次打开,但每次我运行我的应用程序时都会打开。如何启动只是第一次?

public class IntroActivity extends AppIntro {
private PrefManager prefManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addSlide(AppIntroFragment.newInstance("First","This is the first page",
            R.drawable.sugar, ContextCompat.getColor(getApplicationContext(),R.color.colorAccent)));
    addSlide(AppIntroFragment.newInstance("Second","This is the second page",
            R.drawable.baseline_card_giftcard_black_24dp, ContextCompat.getColor(getApplicationContext(),R.color.colorPrimary)));
    addSlide(AppIntroFragment.newInstance("Third","This is the third page",
            R.drawable.baseline_fastfood_black_18dp, ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark)));
}

@Override
public void onDonePressed(Fragment currentFragment) {
    super.onDonePressed(currentFragment);
    Intent intent = new Intent(IntroActivity.this,MainActivity.class);
    startActivity(intent);
}

@Override
public void onSkipPressed(Fragment currentFragment) {
    super.onSkipPressed(currentFragment);

    Intent intent = new Intent(IntroActivity.this,MainActivity.class);
    startActivity(intent);
}
}

1 个答案:

答案 0 :(得分:1)

摘自该库的文档,here可用:

  

最后,像这样声明清单中的活动:

<activity android:name="com.example.example.intro"
android:label="@string/app_intro" />
  

请勿将简介介绍为您的主要应用启动器,除非您希望每次启动应用时都启动该简介。请参阅Wiki,以获取有关如何从主要活动中一次启动简介的示例。

Wiki所指的是:

  

如果上述方法不清楚或您无法实现相同方法,请尝试在MainActivity.java文件中编写以下使用SharedPreferences的代码:-

/* In your onCreate method */
SharedPreferences sp = getSharedPreferences(MyPrefs, Context.MODE_PRIVATE);
    if (!sp.getBoolean("first", false)) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean("first", true);
        editor.apply();
        Intent intent = new Intent(this, IntroActivity.class); // Call the AppIntro java class
        startActivity(intent);
    }

此代码读取一个共享的首选项,如果发现它不存在,或者它的值为false,它将创建或编辑该首选项(以使条件下一次失败),然后打开简介屏幕。