Skip to content

Using the navigation component in Jetpack, also including a splash screen as new Theme

Notifications You must be signed in to change notification settings

alexpadillarosas/Jetpack-4-NavigationComponent

Repository files navigation

Jetpack-4-NavigationComponent

Based on a default project template Fragment + ViewModel.

This app shows the usage of a splash screen and the navigation component, basically passing an object as parameter. This demonstration version uses buttons to send different information to the next fragment(dragon's detail fragment). We also use safeargs to pass the information via navigation controller.

Splash screen

The splash screen is used as a new theme, hence there is no activity for the splash screen which will otherwise make the user wait a defined period of time, before showing the main screen of your app.

create a theme in themes.xml, find it inside res/values/themes do it for both files, adding the following, and set your splash image.

    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/httyd_splash_background</item>
    </style>

next reference it in the AndroidManifest.xml file, change the theme of your entrypoint app class:

<activity android:name=".MainActivity" android:theme="@style/Theme.JetpackNavigation">

Lastly, do not forget to set the original theme(Base application theme, in this example AppTheme) of your MainActivity back, otherwise it will have the image as background. in the onCreate method of your MainActivity, before the super, add:

setTheme(R.style.Theme_JetpackNavigation);

That's all, it will show the splash screen image while your Activity is loading, so the user won't wait any additional time, more than the required to load the MainActivity.

Basic NavigationComponent application

storyboard

Notice that there is no splash activity in the navigation graph.

Splash image shown while the MainActivity is loading (just a simple jpg image: @drawable/httyd_splash_background)

App in action

About

Using the navigation component in Jetpack, also including a splash screen as new Theme

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages