为什么下面的OnboardingSupportFragment在Android中不起作用?

时间:2019-03-30 20:12:48

标签: android

我正在尝试在android中实现OnboardingSupportFragment,但运气不佳。有人知道我能看到哪里出问题的例子吗?

我已经重写了基类并实现了我需要的所有方法。但是我似乎无法弄清楚如何从片段事务中启动片段。

在我的Fragment活动中:

        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.add( R.id.dp_fragment_container, new DPOnboardingFragment());
        transaction.addToBackStack(null);
        transaction.commit();

OnBoardingFragment:

    @Override
    protected int getPageCount() {
        return 1;
    }

    @Override
    protected CharSequence getPageTitle(int pageIndex) {
        Log.d("GET PAGE TITLE", "REQUESTING THE PAGE TITLE");
        return "Welcome to the app!";
    }

    @Override
    protected CharSequence getPageDescription(int pageIndex) {
        Log.d("GET PAGE DESCRIPTION", "REQUESTING THE PAGE DESCRIPTION");
        return "Keen to get stuck in? Here's a couple of helpful tips to allow you to get the most out of the app";
    }

    @Nullable
    @Override
    protected View onCreateBackgroundView(LayoutInflater inflater, ViewGroup container) {
        Log.d("GET PAGE BACKGROUND", "REQUESTING THE PAGE BACKGROUND");
        return inflater.inflate(R.layout.onboarding_background, container);
    }

    @Nullable
    @Override
    protected View onCreateContentView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.onboarding_note_created, container);
    }

    @Nullable
    @Override
    protected View onCreateForegroundView(LayoutInflater inflater, ViewGroup container) {
        return null;
    }

    @Override
    protected void onFinishFragment() {
        super.onFinishFragment();
        // User has seen OnboardingFragment, so mark our SharedPreferences
        // flag as completed so that we don't show our OnboardingFragment
        // the next time the user launches the app.
        SharedPreferences.Editor sharedPreferencesEditor = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
        sharedPreferencesEditor.putBoolean(getString(R.string.is_first_launch), true);
        sharedPreferencesEditor.apply();
    }
}

活动布局文件:

<FrameLayout
    android:name=".DpOnboardingActivity"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/dp_fragment_container"
    android:enabled="true"
    android:exported="true"
    android:theme="@style/Theme.Leanback.Onboarding">
</FrameLayout>

我希望看到类似this的内容。但是我只是了解我的活动背景,所以该片段没有被发布

0 个答案:

没有答案