Hello coders, in this article i will show you simplest way with source code to make Intro Slider for your android app using ViewPager and Fragments in android studio. I will also share real code so you can copy and paste and adjust layout of fragments and make your own Intro Slider for your app.

You can see me coding the intro slider on YouTube tutorial :

How to make adapter for ViewPager:

For your ViewPager you have build adapter that will functionality of sliding between fragments. For this we will user FragmentStatePagerAdapter from class androidx.fragment.app.FragmentStatePagerAdapter. When your adapter extends FragmentStatePagerAdapter you need to implements its two methods:

  • Fragment getItem(int position) : this method will take your fragments and return layout from sliding to your ViewPager.
  • int getCount() : Counter of item / Fragments that passed to adapter.

Source Code for Slider :


package com.raj.introsliderexample;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

public class SliderAdapter extends FragmentStatePagerAdapter {
    public SliderAdapter(@NonNull FragmentManager fm) {
    public SliderAdapter(@NonNull FragmentManager fm, int behavior) {
        super(fm, behavior);
    public Fragment getItem(int position) {
        //add your fragments here
        switch (position) {
            case 0:
                return new ScreenOne();

            case 1:
                return new ScreenTwo();

            case 2:
                return new ScreenThree();

                return new ScreenOne();
    public int getCount() {
        //count of your screen
        return 3;


package com.raj.introsliderexample;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    ViewPager viewPager;
    TextView tv_page_counter, tv_next;

    int total = 3 , count = 1;

    protected void onCreate(Bundle savedInstanceState) {

        //find view by ids
        viewPager = findViewById(R.id.viewpager);
        tv_page_counter = findViewById(R.id.tv_page_counter);
        tv_next = findViewById(R.id.tv_next);

        tv_page_counter.setText( count + " / " + total);

        //hide title

        //set adapter
        viewPager.setAdapter(new SliderAdapter(getSupportFragmentManager()));

        //change counter on scroll
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {


            public void onPageSelected(int position) {
                count = 0;
                count = position + 1;
                tv_page_counter.setText( count + " / " + total);

                if (count == total){

            public void onPageScrollStateChanged(int state) {


        //on last screen change next button to finish / continue

I hope this article will help you to code Intro Slider for your app in android studio. Thanks for visiting. Subscribe my channel to my channel for more coding and life style stuff.

Enjoy coding 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *