belongs to Maven artifact com.android.support:leanback-v17:28.0.0-alpha1
OnboardingSupportFragment
public
abstract
class
OnboardingSupportFragment
extends Fragment
java.lang.Object | ||
↳ | android.support.v4.app.Fragment | |
↳ | android.support.v17.leanback.app.OnboardingSupportFragment |
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(LayoutInflater, ViewGroup)
to provide the background view. Background view has the same size as the screen and the lowest z-order.onCreateContentView(LayoutInflater, ViewGroup)
to provide the contents view. The content view is located in the content area at the center of the screen.onCreateForegroundView(LayoutInflater, ViewGroup)
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:
getPageCount()
to provide the number of pages.getPageTitle(int)
to provide the title of the page.getPageDescription(int)
to provide the description of the page.
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:
- The simplest way is to provide the logo image by calling
setLogoResourceId(int)
to show the default logo animation. This method should be called inonCreateView(LayoutInflater, ViewGroup, Bundle)
. - If the logo animation is complex, then override
onCreateLogoAnimation()
and return theAnimator
object to run.
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 overridingonCreateTitleAnimator()
&
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 overrideonPageChanged(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
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.)
Summary
XML attributes | |
---|---|
LeanbackOnboardingTheme_onboardingDescriptionStyle |
|
LeanbackOnboardingTheme_onboardingHeaderStyle |
|
LeanbackOnboardingTheme_onboardingLogoStyle |
|
LeanbackOnboardingTheme_onboardingNavigatorContainerStyle |
|
LeanbackOnboardingTheme_onboardingPageIndicatorStyle |
|
LeanbackOnboardingTheme_onboardingStartButtonStyle |
|
LeanbackOnboardingTheme_onboardingTheme |
|
LeanbackOnboardingTheme_onboardingTitleStyle |
Public constructors | |
---|---|
OnboardingSupportFragment()
|
Public methods | |
---|---|
final
int
|
getArrowBackgroundColor()
Returns the background color of the arrow if it's set through
|
final
int
|
getArrowColor()
Returns the color of the arrow if it's set through
|
final
int
|
getDescriptionViewTextColor()
Returns the text color of DescriptionView if it's set through
|
final
int
|
getDotBackgroundColor()
Returns the background color of the dot if it's set through
|
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
|
final
int
|
getTitleViewTextColor()
Returns the text color of TitleView if it's set through
|
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 |
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 | |
---|---|
![]()
android.support.v4.app.Fragment
|