How to create OnBoarding Screen within three minutes?

Vikas Kumar
2 min readNov 7, 2020

To create an OnBoarding screen we need to make some files and activities in our application

  1. OnBoarding Activity
  2. slides_layout XML file
  3. SliderAdapter Class

OnBoarding Activity

In the onBoard Activity, we need some of the pallets to run the activity like

  • ViewPager(Slider)
  • Button (Next and Skip to switch to the next screen and skip all the screens respectively)
  • Layouts(Set and design pallets position)

slides_layout XML file

Now create slides XML file where you will show all your Slides. Slides_layout is more like a container to fill views temporarily. Here in this slides_layout.xml, we have demo ImageView, and two TextView to show Slider-Image, Slider-heading and Slider-description respectively.

We have designed this XML file, Now we need to change these pallets dynamically from a java class (Adapter).

SliderAdapter Class

SliderAdapter.java Class is used to show the slides on our main screen with the help of some features like:

  • Context(On which activity we want to show our adapter)
    Just call context and pass the activity on which you want to show your adapter
  • images, headings, description array
  • getCount is an imported method which signifies the number of slides being used (Here in this example we have 5 0–4)
  • isViewFromObject is also an imported method which signifies which object is used of Here we are using objects of ConstraintLayout
  • instantiateItem is an override method that is used to initialize this images, headings and titles with the help of some feature like:
    LayoutInflater(to use design which is created in XML) which is basically a request to use XML file Here we are using sildesLayout(demo xml file)
  • destroyItem is an override method that is used to destroy the previous item created by our instantiateItem method.

Now we are ready to work on our OnBoarding.java file

one last thing to do is to set a constraint on onBoarding that it should be visible to the first time user only(one who opened the app for the first time). It can be done by means of SharedPreferences class variable in your intent to this onBoarding activity method.

Congratulations, OnBoarding Activity is ready to use.

Clap 👏🏻👏🏻 50 times and share the article if you like it. Thank you for giving your valuable time :)

--

--

Vikas Kumar

Android Developer | Actions on Google | GCP | Tech-Blogger | Mentor | Open Source Contributor| CA at Coding Blocks