Skip to content

Most visited

Recently visited

navigation

OnboardingFragment

public abstract class OnboardingFragment
extends Fragment

java.lang.Object
   ↳ android.app.Fragment
     ↳ android.support.v17.leanback.app.OnboardingFragment


An OnboardingFragment 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:

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(LayoutInflater, ViewGroup, Bundle), 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(int, int) 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

OnboardingFragment 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 OnboardingFragment as an overlay to the Activity's theme.
  • Finally, custom subclasses of OnboardingFragment 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.)

Summary

XML attributes

android.support.v17.leanback:onboardingDescriptionStyle Theme attribute for the style of the description text in onboarding screen. 
android.support.v17.leanback:onboardingHeaderStyle Theme attribute for the style of the header in onboarding screen. 
android.support.v17.leanback:onboardingLogoStyle Theme attribute for the style of the logo in onboarding screen. 
android.support.v17.leanback:onboardingNavigatorContainerStyle Theme attribute for the style of the navigator container in onboarding screen. 
android.support.v17.leanback:onboardingPageIndicatorStyle Theme attribute for the style of the page indicator in onboarding screen. 
android.support.v17.leanback:onboardingStartButtonStyle Theme attribute for the style of the start button in onboarding screen. 
android.support.v17.leanback:onboardingTheme Theme attribute for the overall theme used in the onboarding. 
android.support.v17.leanback:onboardingTitleStyle Theme attribute for the style of the title text in onboarding screen. 

Inherited XML attributes

From class android.app.Fragment

Inherited constants

From interface android.content.ComponentCallbacks2

Public constructors

OnboardingFragment()

Public methods

final int getArrowBackgroundColor()

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

final int getArrowColor()

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

final int getDescriptionViewTextColor()

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

final int getDotBackgroundColor()

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

final int getIconResourceId()

Returns the resource id of the main icon.

final int getLogoResourceId()

Returns the resource ID of the splash logo image.

final CharSequence getStartButtonText()

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

final int getTitleViewTextColor()

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

View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Called to have the fragment instantiate its user interface view.

int onProvideTheme()

Returns the theme used for styling the fragment.

void onSaveInstanceState(Bundle outState)

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

void onViewCreated(View view, Bundle savedInstanceState)

Called immediately after onCreateView(LayoutInflater, ViewGroup, Bundle) has returned, but before any saved state has been restored in to the view.

void setArrowBackgroundColor(int color)

Sets the background color of the arrow.

void setArrowColor(int color)

Sets the color of the arrow.

void setDescriptionViewTextColor(int color)

Sets the text color for DescriptionView.

void setDotBackgroundColor(int color)

Sets the background color of the dots.

final void setIconResouceId(int resourceId)

Sets the resource id for the main icon.

final void setLogoResourceId(int id)

Sets the resource ID of the splash logo image.

void setStartButtonText(CharSequence text)

Sets the text on the start button text.

void setTitleViewTextColor(int color)

Sets the text color for TitleView.

Protected methods

final int getCurrentPageIndex()

Returns the index of the current page.

abstract int getPageCount()

Returns the page count.

abstract CharSequence getPageDescription(int pageIndex)

Returns the description of the given page.

abstract CharSequence getPageTitle(int pageIndex)

Returns the title of the given page.

final boolean isLogoAnimationFinished()

Returns whether the logo enter animation is finished.

void moveToNextPage()

Navigates to the next page.

void moveToPreviousPage()

Navigates to the previous page.

abstract View onCreateBackgroundView(LayoutInflater inflater, ViewGroup container)

Called to have the inherited class create background view.

abstract View onCreateContentView(LayoutInflater inflater, ViewGroup container)

Called to have the inherited class create content view.

Animator onCreateDescriptionAnimator()

Provides the entry animation for description view.

Animator onCreateEnterAnimation()

Called to have the inherited class create its enter animation.

abstract View onCreateForegroundView(LayoutInflater inflater, ViewGroup container)

Called to have the inherited class create foreground view.

Animator onCreateLogoAnimation()

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

Animator onCreateTitleAnimator()

Provides the entry animation for title view.

void onFinishFragment()

Called when the onboarding flow finishes.

void onLogoAnimationFinished()

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 class android.app.Fragment
From class java.lang.Object
From interface android.content.ComponentCallbacks2
From interface android.view.View.OnCreateContextMenuListener
From interface android.content.ComponentCallbacks

XML attributes

android.support.v17.leanback:onboardingDescriptionStyle

Theme attribute for the style of the description text in onboarding screen. Default is Widget_Leanback_OnboardingDescriptionStyle.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android.support.v17.leanback:onboardingHeaderStyle

Theme attribute for the style of the header in onboarding screen. Default is Widget_Leanback_OnboardingHeaderStyle.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android.support.v17.leanback:onboardingLogoStyle

Theme attribute for the style of the logo in onboarding screen. Default is Widget_Leanback_OnboardingLogoStyle.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android.support.v17.leanback:onboardingNavigatorContainerStyle

Theme attribute for the style of the navigator container in onboarding screen. Default is Widget_Leanback_OnboardingNavigatorContainerStyle.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android.support.v17.leanback:onboardingPageIndicatorStyle

Theme attribute for the style of the page indicator in onboarding screen. Default is Widget_Leanback_OnboardingPageIndicatorStyle.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android.support.v17.leanback:onboardingStartButtonStyle

Theme attribute for the style of the start button in onboarding screen. Default is Widget_Leanback_OnboardingStartButtonStyle.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android.support.v17.leanback:onboardingTheme

Theme attribute for the overall theme used in the onboarding. The Leanback themes set the default for this, but a custom theme that does not derive from a leanback theme can set this to @style/Theme.Leanback.Onboarding in order to specify the default OnboardingFragment styles.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android.support.v17.leanback:onboardingTitleStyle

Theme attribute for the style of the title text in onboarding screen. Default is Widget_Leanback_OnboardingTitleStyle.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

Public constructors

OnboardingFragment

added in version 24.0.0
OnboardingFragment ()

Public methods

getArrowBackgroundColor

int getArrowBackgroundColor ()

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

Returns
int

getArrowColor

int getArrowColor ()

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

Returns
int

getDescriptionViewTextColor

int getDescriptionViewTextColor ()

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

Returns
int

getDotBackgroundColor

int getDotBackgroundColor ()

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

Returns
int

getIconResourceId

int getIconResourceId ()

Returns the resource id of the main icon.

Returns
int

getLogoResourceId

added in version 24.0.0
int getLogoResourceId ()

Returns the resource ID of the splash logo image.

Returns
int The resource ID of the splash logo image.

getStartButtonText

CharSequence getStartButtonText ()

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

Returns
CharSequence

getTitleViewTextColor

int getTitleViewTextColor ()

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

Returns
int

onCreateView

View onCreateView (LayoutInflater inflater, 
                ViewGroup container, 
                Bundle savedInstanceState)

Called to have the fragment instantiate its user interface view. This is optional, and non-graphical fragments can return null (which is the default implementation). This will be called between onCreate(Bundle) and onActivityCreated(Bundle).

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

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

container ViewGroup: 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.

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

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

onProvideTheme

added in version 24.0.0
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

void onSaveInstanceState (Bundle outState)

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of 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(Bundle), onCreateView(LayoutInflater, ViewGroup, Bundle), and onActivityCreated(Bundle).

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
outState Bundle: Bundle in which to place your saved state.

onViewCreated

void onViewCreated (View view, 
                Bundle savedInstanceState)

Called immediately after onCreateView(LayoutInflater, ViewGroup, Bundle) 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
view View: The View returned by onCreateView(LayoutInflater, ViewGroup, Bundle).

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

setArrowBackgroundColor

void setArrowBackgroundColor (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
color int: the color to use for arrow background

setArrowColor

void setArrowColor (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
color int: the color to use for arrow background

setDescriptionViewTextColor

void setDescriptionViewTextColor (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
color int: the color to use as the text color for DescriptionView

setDotBackgroundColor

void setDotBackgroundColor (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
color int: the color to use for dot backgrounds

setIconResouceId

void setIconResouceId (int resourceId)

Sets the resource id for the main icon.

Parameters
resourceId int

setLogoResourceId

added in version 24.0.0
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
id int: The resource ID of the logo image.

setStartButtonText

void setStartButtonText (CharSequence text)

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

Parameters
text CharSequence: the start button text

setTitleViewTextColor

void setTitleViewTextColor (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
color int: the color to use as the text color for TitleView

Protected methods

getCurrentPageIndex

added in version 24.0.0
int getCurrentPageIndex ()

Returns the index of the current page.

Returns
int The index of the current page.

getPageCount

added in version 24.0.0
int getPageCount ()

Returns the page count.

Returns
int The page count.

getPageDescription

added in version 24.0.0
CharSequence getPageDescription (int pageIndex)

Returns the description of the given page.

Parameters
pageIndex int: The page index.

Returns
CharSequence The description of the page.

getPageTitle

added in version 24.0.0
CharSequence getPageTitle (int pageIndex)

Returns the title of the given page.

Parameters
pageIndex int: The page index.

Returns
CharSequence The title of the page.

isLogoAnimationFinished

added in version 25.4.0
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 version 25.4.0
void moveToNextPage ()

Navigates to the next page.

moveToPreviousPage

added in version 25.4.0
void moveToPreviousPage ()

Navigates to the previous page.

onCreateBackgroundView

added in version 24.0.0
View onCreateBackgroundView (LayoutInflater inflater, 
                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(LayoutInflater, ViewGroup, Bundle).

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

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

Returns
View The background view for the onboarding screen, or null.

onCreateContentView

added in version 24.0.0
View onCreateContentView (LayoutInflater inflater, 
                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(LayoutInflater, ViewGroup, Bundle).

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

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

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

Returns
View The content view for the onboarding screen, or null.

onCreateDescriptionAnimator

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.

Returns
Animator

onCreateEnterAnimation

added in version 24.0.0
Animator onCreateEnterAnimation ()

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

Returns
Animator The Animator object which runs the page enter animation.

onCreateForegroundView

added in version 24.0.0
View onCreateForegroundView (LayoutInflater inflater, 
                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(LayoutInflater, ViewGroup, Bundle).

This foreground view would have the highest z-order.

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

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

Returns
View The foreground view for the onboarding screen, or null.

onCreateLogoAnimation

added in version 24.0.0
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(int). If this returns null, the logo animation is skipped.

Returns
Animator The Animator object which runs the logo animation.

onCreateTitleAnimator

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.

Returns
Animator

onFinishFragment

added in version 24.0.0
void onFinishFragment ()

Called when the onboarding flow finishes.

onLogoAnimationFinished

added in version 25.4.0
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 version 24.0.0
void onPageChanged (int newPage, 
                int previousPage)

Called when the page has been changed.

Parameters
newPage int: The new page.

previousPage int: The previous page.

startEnterAnimation

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
force boolean: true if enter animation has to be performed regardless of whether it's been done in the past, false otherwise

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.