Jul 18 2018
, Kotlin 1.2, Android 4.4, Android Studio 3Kotlin 1.2, Android 4.4, Android Studio 3
In this tutorial, you’ll learn how to use Slices, which allow you to embed parts of your app into viewers like the Google Search app and Google Assistant.
By Ahmed Tarek.
Build and run again. Notice that the notification icon color is changed from the accent color of the Slice Viewer app to the accent color you have set:
Display Modes
Slice viewers can display Slices in three display modes:
You’ve aleady made your Slice compatible with the three modes by adding the following a summary to the Slice header within the apply block. The summary will be shown in the small mode instead of the subtitle.
Note: If you have not set a header to your ListBuilder, the first row added to your ListBuilder is displayed instead.
Note: If you have not set a header to your ListBuilder, the first row added to your ListBuilder is displayed instead.
Build and run in the Slice Viewer app.
Put your Slice in Small mode by tapping on the right-top icon in the Slice Viewer app and select small; you will see a screen like this:
Put your Slice in the Shortcut mode by tapping on the right-top icon in the Slice Viewer app and select shortcut; you will see a screen like this:
And with that, you have finished your Slices tutorial!
Where to Go From Here?
You can download the completed project using the Download Materials button at the top or bottom of this tutorial.
Note: You’ll need to complete the instructions in the Slice viewer and Let the Slice viewer show your Slice sections to be able to run the final project.
During this tutorial you learned how to:
Create a Slice for a bookstore app.
Show the Slice on the surface of the Slice Viewer app.
Make the Slice interactive by adding a notification icon to let the user enable or disable notification without opening the app.
Make the Slice compatible with the different display modes.
Update the Slice with new data.
While you have learned how to incorporate Slices, note that, as of the writing this tutorial, the official Android documentation states: “Slices will start appearing soon for users, but you can start building today.”
You may also find it helpful to learn about RangeBuilder, which you can read about here.
And since Slices are a way to enhance App Actions, you may want to know more about App Actions, which you can learn about here.
Feel free to share your feedback or ask any questions in the comments below or in the forums!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.