OnboardingSupportFragment


public abstract class OnboardingSupportFragment extends Fragment


An OnboardingSupportFragment provides a common and simple way to build onboarding screen for applications.

Building the screen

The view structure of onboarding screen is composed of the common parts and custom parts. The common parts are composed of icon, title, description and page navigator and the custom parts are composed of background, contents and foreground.

To build the screen views, the inherited class should override:

  • onCreateBackgroundView to provide the background view. Background view has the same size as the screen and the lowest z-order.
  • onCreateContentView to provide the contents view. The content view is located in the content area at the center of the screen.
  • onCreateForegroundView to provide the foreground view. Foreground view has the same size as the screen and the highest z-order

Each of these methods can return null if the application doesn't want to provide it.

Page information

The onboarding screen may have several pages which explain the functionality of the application. The inherited class should provide the page information by overriding the methods:

Note that the information is used in onCreateView, so should be initialized before calling super.onCreateView.

Animation

Onboarding screen has three kinds of animations: Logo Splash Animation When onboarding screen appears, the logo splash animation is played by default. The animation fades in the logo image, pauses in a few seconds and fades it out.

In most cases, the logo animation needs to be customized because the logo images of applications are different from each other, or some applications may want to show their own animations.

The logo animation can be customized in two ways:

If the inherited class provides neither the logo image nor the animation, the logo animation will be omitted.

Page enter animation After logo animation finishes, page enter animation starts, which causes the header section - title and description views to fade and slide in. Users can override the default fade + slide animation by overriding onCreateTitleAnimator&onCreateDescriptionAnimator. By default we don't animate the custom views but users can provide animation by overriding onCreateEnterAnimation. Page change animation When the page changes, the default animations of the title and description are played. The inherited class can override onPageChanged to start the custom animations.

Finishing the screen

If the user finishes the onboarding screen after navigating all the pages, onFinishFragment is called. The inherited class can override this method to show another fragment or activity, or just remove this fragment.

Theming

OnboardingSupportFragment must have access to an appropriate theme. Specifically, the fragment must receive Theme_Leanback_Onboarding, or a theme whose parent is set to that theme. Themes can be provided in one of three ways:

  • The simplest way is to set the theme for the host Activity to the Onboarding theme or a theme that derives from it.
  • If the Activity already has a theme and setting its parent theme is inconvenient, the existing Activity theme can have an entry added for the attribute LeanbackOnboardingTheme_onboardingTheme. If present, this theme will be used by OnboardingSupportFragment as an overlay to the Activity's theme.
  • Finally, custom subclasses of OnboardingSupportFragment may provide a theme through the onProvideTheme method. This can be useful if a subclass is used across multiple Activities.

If the theme is provided in multiple ways, the onProvideTheme override has priority, followed by the Activity's theme. (Themes whose parent theme is already set to the onboarding theme do not need to set the onboardingTheme attribute; if set, it will be ignored.) onboardingThemeonboardingHeaderStyleonboardingTitleStyleonboardingDescriptionStyleonboardingNavigatorContainerStyleonboardingPageIndicatorStyleonboardingStartButtonStyleonboardingLogoStyle

Summary

Public constructors

Public methods

final @ColorInt int

Returns the background color of the arrow if it's set through setArrowBackgroundColor.

final @ColorInt int

Returns the color of the arrow if it's set through setArrowColor.

final @ColorInt int

Returns the text color of DescriptionView if it's set through setDescriptionViewTextColor.

final @ColorInt int

Returns the background color of the dot if it's set through setDotBackgroundColor.

final int

Returns the resource id of the main icon.

final int

Returns the resource ID of the splash logo image.

final @Nullable CharSequence

Returns the start button text if it's set through setStartButtonText}.

final @ColorInt int

Returns the text color of TitleView if it's set through setTitleViewTextColor.

@Nullable View
onCreateView(
    @NonNull LayoutInflater inflater,
    @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState
)

Called to have the fragment instantiate its user interface view.

int

Returns the theme used for styling the fragment.

void

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance if its process is restarted.

void
onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)

Called immediately after onCreateView has returned, but before any saved state has been restored in to the view.

void

Sets the background color of the arrow.

void
setArrowColor(@ColorInt int color)

Sets the color of the arrow.

void

Sets the text color for DescriptionView.

void

Sets the background color of the dots.

final void
setIconResouceId(int resourceId)

Sets the resource id for the main icon.

final void

Sets the resource ID of the splash logo image.

void

Sets the text on the start button text.

void

Sets the text color for TitleView.

Protected methods

final int

Returns the index of the current page.

abstract int

Returns the page count.

abstract @Nullable CharSequence
getPageDescription(int pageIndex)

Returns the description of the given page.

abstract @Nullable CharSequence
getPageTitle(int pageIndex)

Returns the title of the given page.

final boolean

Returns whether the logo enter animation is finished.

void

Navigates to the next page.

void

Navigates to the previous page.

abstract @Nullable View
onCreateBackgroundView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create background view.

abstract @Nullable View
onCreateContentView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create content view.

@NonNull Animator

Provides the entry animation for description view.

@Nullable Animator

Called to have the inherited class create its enter animation.

abstract @Nullable View
onCreateForegroundView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create foreground view.

@Nullable Animator

Called to have the inherited class create its own logo animation.

@NonNull Animator

Provides the entry animation for title view.

void

Called when the onboarding flow finishes.

void

Called immediately after the logo animation is complete or no logo animation is specified.

void
onPageChanged(int newPage, int previousPage)

Called when the page has been changed.

final void
startEnterAnimation(boolean force)

Called to start entrance transition.

Inherited methods

From androidx.activity.result.ActivityResultCaller
abstract ActivityResultLauncher<I>
<I, O> registerForActivityResult(
    ActivityResultContract<I, O> contract,
    ActivityResultCallback<O> callback
)

Register a request to start an activity for result, designated by the given contract.

From android.content.ComponentCallbacks
abstract void
abstract void
From androidx.fragment.app.Fragment
void
dump(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable String[] args
)

Print the Fragments's state into the given stream.

final boolean

Subclasses can not override equals().

final @Nullable FragmentActivity

Return the FragmentActivity this fragment is currently associated with.

boolean

Returns whether the the exit transition and enter transition overlap or not.

boolean

Returns whether the the return transition and reenter transition overlap or not.

final @Nullable Bundle

Return the arguments supplied when the fragment was instantiated, if any.

final @NonNull FragmentManager

Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

@Nullable Context

Return the Context this fragment is currently associated with.

@NonNull CreationExtras

The Fragment's arguments when this is first called will be used as the defaults to any androidx.lifecycle.SavedStateHandle passed to a view model created using this extra.

@NonNull ViewModelProvider.Factory
@Nullable Object

Returns the Transition that will be used to move Views into the initial scene.

@Nullable Object

Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.

final @Nullable FragmentManager

This method is deprecated.

This has been removed in favor of getParentFragmentManager() which throws an IllegalStateException if the FragmentManager is null.

final @Nullable Object

Return the host object of this fragment.

final int

Return the identifier this fragment is known by.

final @NonNull LayoutInflater

Returns the cached LayoutInflater used to inflate Views of this Fragment.

@NonNull Lifecycle

Overriding this method is no longer supported and this method will be made final in a future version of Fragment.

@NonNull LoaderManager

This method is deprecated.

Use LoaderManager.getInstance(this).

final @Nullable Fragment

Returns the parent Fragment containing this Fragment.

final @NonNull FragmentManager

Return the FragmentManager for interacting with fragments associated with this fragment's activity.

@Nullable Object

Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack.

final @NonNull Resources

Return requireActivity().getResources().

final boolean

This method is deprecated.

Instead of retaining the Fragment itself, use a non-retained Fragment and keep retained state in a ViewModel attached to that Fragment.

@Nullable Object

Returns the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.

final @NonNull SavedStateRegistry
@Nullable Object

Returns the Transition that will be used for shared elements transferred into the content Scene.

@Nullable Object

Return the Transition that will be used for shared elements transferred back during a pop of the back stack.

final @NonNull String
getString(@StringRes int resId)

Return a localized string from the application's package's default string table.

final @NonNull String
getString(@StringRes int resId, @Nullable Object[] formatArgs)

Return a localized formatted string from the application's package's default string table, substituting the format arguments as defined in java.util.Formatter and format.

final @Nullable String

Get the tag name of the fragment, if specified.

final @Nullable Fragment

This method is deprecated.

Instead of using a target fragment to pass results, use setFragmentResult to deliver results to FragmentResultListener instances registered by other fragments via setFragmentResultListener.

final int

This method is deprecated.

When using the target fragment replacement of setFragmentResultListener and setFragmentResult, consider using setArguments to pass a requestKey if you need to support dynamic request keys.

final @NonNull CharSequence
getText(@StringRes int resId)

Return a localized, styled CharSequence from the application's package's default string table.

boolean

This method is deprecated.

Use setMaxLifecycle instead.

@Nullable View

Get the root view for the fragment's layout (the one returned by onCreateView), if provided.

@NonNull LifecycleOwner

Get a LifecycleOwner that represents the Fragment's View lifecycle.

@NonNull LiveData<LifecycleOwner>

Retrieve a LiveData which allows you to observe the lifecycle of the Fragment's View.

@NonNull ViewModelStore

Returns the ViewModelStore associated with this Fragment

final int

Subclasses can not override hashCode().

static @NonNull Fragment

This method is deprecated.

Use getFragmentFactory and instantiate

static @NonNull Fragment
instantiate(
    @NonNull Context context,
    @NonNull String fname,
    @Nullable Bundle args
)

This method is deprecated.

Use getFragmentFactory and instantiate, manually calling setArguments on the returned Fragment.

final boolean

Return true if the fragment is currently added to its activity.

final boolean

Return true if the fragment has been explicitly detached from the UI.

final boolean

Return true if the fragment has been hidden.

final boolean

Return true if the layout is included as part of an activity view hierarchy via the tag.

final boolean

Return true if this fragment is currently being removed from its activity.

final boolean

Return true if the fragment is in the resumed state.

final boolean

Returns true if this fragment is added and its state has already been saved by its host.

final boolean

Return true if the fragment is currently visible to the user.

void

This method is deprecated.

use onViewCreated for code touching the view created by onCreateView and onCreate for other initialization.

void
onActivityResult(int requestCode, int resultCode, @Nullable Intent data)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

void

This method is deprecated.

See onAttach.

void

Called when a fragment is first attached to its context.

void

This method is deprecated.

The responsibility for listening for fragments being attached has been moved to FragmentManager.

void
boolean

This hook is called whenever an item in a context menu is selected.

void

Called to do initial creation of a fragment.

@Nullable Animation
@MainThread
onCreateAnimation(int transit, boolean enter, int nextAnim)

Called when a fragment loads an animation.

@Nullable Animator
@MainThread
onCreateAnimator(int transit, boolean enter, int nextAnim)

Called when a fragment loads an animator.

void

Called when a context menu for the view is about to be shown.

void

This method is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

void

Called when the fragment is no longer in use.

void

This method is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

void

Called when the view previously created by onCreateView has been detached from the fragment.

void

Called when the fragment is no longer attached to its activity.

@NonNull LayoutInflater
onGetLayoutInflater(@Nullable Bundle savedInstanceState)

Returns the LayoutInflater used to inflate Views of this Fragment.

void
@MainThread
onHiddenChanged(boolean hidden)

Called when the hidden state (as returned by isHidden of the fragment or another fragment in its hierarchy has changed.

void
@UiThread
@CallSuper
onInflate(
    @NonNull Activity activity,
    @NonNull AttributeSet attrs,
    @Nullable Bundle savedInstanceState
)

This method is deprecated.

See onInflate.

void
@UiThread
@CallSuper
onInflate(
    @NonNull Context context,
    @NonNull AttributeSet attrs,
    @Nullable Bundle savedInstanceState
)

Called when a fragment is being created as part of a view layout inflation, typically from setting the content view of an activity.

void
void
onMultiWindowModeChanged(boolean isInMultiWindowMode)

Called when the Fragment's activity changes from fullscreen mode to multi-window mode and visa-versa.

boolean

This method is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

void

This method is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

void

Called when the Fragment is no longer resumed.

void
onPictureInPictureModeChanged(boolean isInPictureInPictureMode)

Called by the system when the activity changes to and from picture-in-picture mode.

void

This method is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

void
@MainThread
onPrimaryNavigationFragmentChanged(
    boolean isPrimaryNavigationFragment
)

Callback for when the primary navigation state of this Fragment has changed.

void
onRequestPermissionsResult(
    int requestCode,
    @NonNull String[] permissions,
    @NonNull int[] grantResults
)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

void

Called when the fragment is visible to the user and actively running.

void

Called when the Fragment is visible to the user.

void

Called when the Fragment is no longer started.

void

Called when all saved state has been restored into the view hierarchy of the fragment.

void

Postpone the entering Fragment transition until startPostponedEnterTransition or executePendingTransactions has been called.

final void
postponeEnterTransition(long duration, @NonNull TimeUnit timeUnit)

Postpone the entering Fragment transition for a given amount of time and then call startPostponedEnterTransition.

final @NonNull ActivityResultLauncher<I>
@MainThread
<I, O> registerForActivityResult(
    @NonNull ActivityResultContract<I, O> contract,
    @NonNull ActivityResultCallback<O> callback
)

Register a request to start an activity for result, designated by the given contract.

final @NonNull ActivityResultLauncher<I>
@MainThread
<I, O> registerForActivityResult(
    @NonNull ActivityResultContract<I, O> contract,
    @NonNull ActivityResultRegistry registry,
    @NonNull ActivityResultCallback<O> callback
)

Register a request to start an activity for result, designated by the given contract.

void

Registers a context menu to be shown for the given view (multiple views can show the context menu).

final void
requestPermissions(@NonNull String[] permissions, int requestCode)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

final @NonNull FragmentActivity

Return the FragmentActivity this fragment is currently associated with.

final @NonNull Bundle

Return the arguments supplied when the fragment was instantiated.

final @NonNull Context

Return the Context this fragment is currently associated with.

final @NonNull FragmentManager

This method is deprecated.

This has been renamed to getParentFragmentManager() to make it clear that you are accessing the FragmentManager that contains this Fragment and not the FragmentManager associated with child Fragments.

final @NonNull Object

Return the host object of this fragment.

final @NonNull Fragment

Returns the parent Fragment containing this Fragment.

final @NonNull View

Get the root view for the fragment's layout (the one returned by onCreateView).

void

Sets whether the the exit transition and enter transition overlap or not.

void

Sets whether the the return transition and reenter transition overlap or not.

void

Supply the construction arguments for this fragment.

void

When custom transitions are used with Fragments, the enter transition callback is called when this Fragment is attached or detached when not popping the back stack.

void

Sets the Transition that will be used to move Views into the initial scene.

void

When custom transitions are used with Fragments, the exit transition callback is called when this Fragment is attached or detached when popping the back stack.

void

Sets the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.

void
setHasOptionsMenu(boolean hasMenu)

This method is deprecated.

This method is no longer needed when using a MenuProvider to provide a Menu to your activity, which replaces onCreateOptionsMenu as the recommended way to provide a consistent, optionally Lifecycle-aware, and modular way to handle menu creation and item selection.

void

Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned by FragmentManager.saveFragmentInstanceState.

void
setMenuVisibility(boolean menuVisible)

Set a hint for whether this fragment's menu should be visible.

void

Sets the Transition that will be used to move Views in to the scene when returning due to popping a back stack.

void
setRetainInstance(boolean retain)

This method is deprecated.

Instead of retaining the Fragment itself, use a non-retained Fragment and keep retained state in a ViewModel attached to that Fragment.

void

Sets the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.

void

Sets the Transition that will be used for shared elements transferred into the content Scene.

void

Sets the Transition that will be used for shared elements transferred back during a pop of the back stack.

void
setTargetFragment(@Nullable Fragment fragment, int requestCode)

This method is deprecated.

Instead of using a target fragment to pass results, the fragment requesting a result should use setFragmentResultListener to register a FragmentResultListener with a requestKey using its parent fragment manager.

void
setUserVisibleHint(boolean isVisibleToUser)

This method is deprecated.

If you are manually calling this method, use setMaxLifecycle instead.

boolean

Gets whether you should show UI with rationale before requesting a permission.

void

Call startActivity from the fragment's containing Activity.

void

Call startActivity from the fragment's containing Activity.

void
startActivityForResult(@NonNull Intent intent, int requestCode)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

void
startActivityForResult(
    @NonNull Intent intent,
    int requestCode,
    @Nullable Bundle options
)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

void
startIntentSenderForResult(
    @NonNull IntentSender intent,
    int requestCode,
    @Nullable Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    @Nullable Bundle options
)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

void

Begin postponed transitions after postponeEnterTransition was called.

@NonNull String
void

Prevents a context menu to be shown for the given view.

From androidx.lifecycle.HasDefaultViewModelProviderFactory
From androidx.lifecycle.LifecycleOwner
abstract Lifecycle
From androidx.savedstate.SavedStateRegistryOwner
From android.view.View.OnCreateContextMenuListener
abstract void
From androidx.lifecycle.ViewModelStoreOwner

Public constructors

OnboardingSupportFragment

Added in 1.1.0
public OnboardingSupportFragment()

Public methods

getArrowBackgroundColor

Added in 1.1.0
public final @ColorInt int getArrowBackgroundColor()

Returns the background color of the arrow if it's set through setArrowBackgroundColor. If no color was set, transparent is returned.

getArrowColor

Added in 1.1.0
public final @ColorInt int getArrowColor()

Returns the color of the arrow if it's set through setArrowColor. If no color was set, transparent is returned.

getDescriptionViewTextColor

Added in 1.1.0
public final @ColorInt int getDescriptionViewTextColor()

Returns the text color of DescriptionView if it's set through setDescriptionViewTextColor. If no color was set, transparent is returned.

getDotBackgroundColor

Added in 1.1.0
public final @ColorInt int getDotBackgroundColor()

Returns the background color of the dot if it's set through setDotBackgroundColor. If no color was set, transparent is returned.

getIconResourceId

Added in 1.1.0
public final int getIconResourceId()

Returns the resource id of the main icon.

getLogoResourceId

Added in 1.1.0
public final int getLogoResourceId()

Returns the resource ID of the splash logo image.

Returns
int

The resource ID of the splash logo image.

getStartButtonText

Added in 1.1.0
public final @Nullable CharSequence getStartButtonText()

Returns the start button text if it's set through setStartButtonText}. If no string was set, null is returned.

getTitleViewTextColor

Added in 1.1.0
public final @ColorInt int getTitleViewTextColor()

Returns the text color of TitleView if it's set through setTitleViewTextColor. If no color was set, transparent is returned.

onCreateView

public @Nullable View onCreateView(
    @NonNull LayoutInflater inflater,
    @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState
)

Called to have the fragment instantiate its user interface view. This is optional, and non-graphical fragments can return null. This will be called between onCreate and onViewCreated.

A default View can be returned by calling Fragment in your constructor. Otherwise, this method returns null.

It is recommended to only inflate the layout in this method and move logic that operates on the returned View to onViewCreated.

If you return a View from here, you will later be called in onDestroyView when the view is being released.

Parameters
@NonNull LayoutInflater inflater

The LayoutInflater object that can be used to inflate any views in the fragment,

@Nullable ViewGroup container

If non-null, this is the parent view that the fragment's UI should be attached to. The fragment should not add the view itself, but this can be used to generate the LayoutParams of the view.

@Nullable Bundle savedInstanceState

If non-null, this fragment is being re-constructed from a previous saved state as given here.

Returns
@Nullable View

Return the View for the fragment's UI, or null.

onProvideTheme

Added in 1.1.0
public int onProvideTheme()

Returns the theme used for styling the fragment. The default returns -1, indicating that the host Activity's theme should be used.

Returns
int

The theme resource ID of the theme to use in this fragment, or -1 to use the host Activity's theme.

onSaveInstanceState

public void onSaveInstanceState(@NonNull Bundle outState)

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance if its process is restarted. If a new instance of the fragment later needs to be created, the data you place in the Bundle here will be available in the Bundle given to onCreate, onCreateView, and onViewCreated.

This corresponds to Activity.onSaveInstanceState(Bundle) and most of the discussion there applies here as well. Note however: this method may be called at any time before onDestroy. There are many situations where a fragment may be mostly torn down (such as when placed on the back stack with no UI showing), but its state will not be saved until its owning activity actually needs to save its state.

Parameters
@NonNull Bundle outState

Bundle in which to place your saved state.

onViewCreated

public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)

Called immediately after onCreateView has returned, but before any saved state has been restored in to the view. This gives subclasses a chance to initialize themselves once they know their view hierarchy has been completely created. The fragment's view hierarchy is not however attached to its parent at this point.

Parameters
@NonNull View view

The View returned by onCreateView.

@Nullable Bundle savedInstanceState

If non-null, this fragment is being re-constructed from a previous saved state as given here.

setArrowBackgroundColor

Added in 1.1.0
public void setArrowBackgroundColor(@ColorInt int color)

Sets the background color of the arrow. If not set, the default color from attr PagingIndicator_arrowBgColor in the theme will be used.

Parameters
@ColorInt int color

the color to use for arrow background

setArrowColor

Added in 1.1.0
public void setArrowColor(@ColorInt int color)

Sets the color of the arrow. This color will supersede the color set in the theme attribute PagingIndicator_arrowColor if provided. If none of these two are set, the arrow will have its original bitmap color.

Parameters
@ColorInt int color

the color to use for arrow background

setDescriptionViewTextColor

Added in 1.1.0
public void setDescriptionViewTextColor(@ColorInt int color)

Sets the text color for DescriptionView. If not set, the default textColor set in style referenced by attr onboardingDescriptionStyle will be used.

Parameters
@ColorInt int color

the color to use as the text color for DescriptionView

setDotBackgroundColor

Added in 1.1.0
public void setDotBackgroundColor(@ColorInt int color)

Sets the background color of the dots. If not set, the default color from attr PagingIndicator_dotBgColor in the theme will be used.

Parameters
@ColorInt int color

the color to use for dot backgrounds

setIconResouceId

Added in 1.1.0
public final void setIconResouceId(int resourceId)

Sets the resource id for the main icon.

setLogoResourceId

Added in 1.1.0
public final void setLogoResourceId(int id)

Sets the resource ID of the splash logo image. If the logo resource id set, the default logo splash animation will be played.

Parameters
int id

The resource ID of the logo image.

setStartButtonText

Added in 1.1.0
public void setStartButtonText(@Nullable CharSequence text)

Sets the text on the start button text. If not set, the default text set in LeanbackOnboardingTheme_onboardingStartButtonStyle will be used.

Parameters
@Nullable CharSequence text

the start button text

setTitleViewTextColor

Added in 1.1.0
public void setTitleViewTextColor(@ColorInt int color)

Sets the text color for TitleView. If not set, the default textColor set in style referenced by attr onboardingTitleStyle will be used.

Parameters
@ColorInt int color

the color to use as the text color for TitleView

Protected methods

getCurrentPageIndex

Added in 1.1.0
protected final int getCurrentPageIndex()

Returns the index of the current page.

Returns
int

The index of the current page.

getPageCount

Added in 1.1.0
protected abstract int getPageCount()

Returns the page count.

Returns
int

The page count.

getPageDescription

Added in 1.1.0
protected abstract @Nullable CharSequence getPageDescription(int pageIndex)

Returns the description of the given page.

Parameters
int pageIndex

The page index.

Returns
@Nullable CharSequence

The description of the page.

getPageTitle

Added in 1.1.0
protected abstract @Nullable CharSequence getPageTitle(int pageIndex)

Returns the title of the given page.

Parameters
int pageIndex

The page index.

Returns
@Nullable CharSequence

The title of the page.

isLogoAnimationFinished

Added in 1.1.0
protected final boolean isLogoAnimationFinished()

Returns whether the logo enter animation is finished.

Returns
boolean

true if the logo enter transition is finished, false otherwise

moveToNextPage

Added in 1.1.0
protected void moveToNextPage()

Navigates to the next page.

moveToPreviousPage

Added in 1.1.0
protected void moveToPreviousPage()

Navigates to the previous page.

onCreateBackgroundView

Added in 1.1.0
protected abstract @Nullable View onCreateBackgroundView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create background view. This is optional and the fragment which doesn't have the background view can return null. This is called inside onCreateView.

Parameters
@NonNull LayoutInflater inflater

The LayoutInflater object that can be used to inflate the views,

@NonNull ViewGroup container

The parent view that the additional views are attached to.The fragment should not add the view by itself.

Returns
@Nullable View

The background view for the onboarding screen, or null.

onCreateContentView

Added in 1.1.0
protected abstract @Nullable View onCreateContentView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create content view. This is optional and the fragment which doesn't have the content view can return null. This is called inside onCreateView.

The content view would be located at the center of the screen.

Parameters
@NonNull LayoutInflater inflater

The LayoutInflater object that can be used to inflate the views,

@NonNull ViewGroup container

The parent view that the additional views are attached to.The fragment should not add the view by itself.

Returns
@Nullable View

The content view for the onboarding screen, or null.

onCreateDescriptionAnimator

Added in 1.1.0
protected @NonNull Animator onCreateDescriptionAnimator()

Provides the entry animation for description view. This allows users to override the default fade and slide animation. Returning null will disable the animation.

onCreateEnterAnimation

Added in 1.1.0
protected @Nullable Animator onCreateEnterAnimation()

Called to have the inherited class create its enter animation. The start animation runs after logo animation ends.

Returns
@Nullable Animator

The Animator object which runs the page enter animation.

onCreateForegroundView

Added in 1.1.0
protected abstract @Nullable View onCreateForegroundView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create foreground view. This is optional and the fragment which doesn't need the foreground view can return null. This is called inside onCreateView.

This foreground view would have the highest z-order.

Parameters
@NonNull LayoutInflater inflater

The LayoutInflater object that can be used to inflate the views,

@NonNull ViewGroup container

The parent view that the additional views are attached to.The fragment should not add the view by itself.

Returns
@Nullable View

The foreground view for the onboarding screen, or null.

onCreateLogoAnimation

Added in 1.1.0
protected @Nullable Animator onCreateLogoAnimation()

Called to have the inherited class create its own logo animation.

This is called only if the logo image resource ID is not set by setLogoResourceId. If this returns null, the logo animation is skipped.

Returns
@Nullable Animator

The Animator object which runs the logo animation.

onCreateTitleAnimator

Added in 1.1.0
protected @NonNull Animator onCreateTitleAnimator()

Provides the entry animation for title view. This allows users to override the default fade and slide animation. Returning null will disable the animation.

onFinishFragment

Added in 1.1.0
protected void onFinishFragment()

Called when the onboarding flow finishes.

onLogoAnimationFinished

Added in 1.1.0
protected void onLogoAnimationFinished()

Called immediately after the logo animation is complete or no logo animation is specified. This method can also be called when the activity is recreated, i.e. when no logo animation are performed. By default, this method will hide the logo view and start the entrance animation for this fragment. Overriding subclasses can provide their own data loading logic as to when the entrance animation should be executed.

onPageChanged

Added in 1.1.0
protected void onPageChanged(int newPage, int previousPage)

Called when the page has been changed.

Parameters
int newPage

The new page.

int previousPage

The previous page.

startEnterAnimation

Added in 1.1.0
protected final void startEnterAnimation(boolean force)

Called to start entrance transition. This can be called by subclasses when the logo animation and data loading is complete. If force flag is set to false, it will only start the animation if it's not already done yet. Otherwise, it will always start the enter animation. In both cases, the logo view will hide and the rest of fragment views become visible after this call.

Parameters
boolean force

true if enter animation has to be performed regardless of whether it's been done in the past, false otherwise