How To Make The First Slide Intro After Installation - Android Studio (Java)




Android Manifest.XML

xml version="1.0" encoding="utf-8"?>
 xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:dist="http://schemas.android.com/apk/distribution"
    package="ronny.example.slider">

     dist:instant="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="Slider Apps"
            android:theme="@style/AppTheme.NoActionBar">
            
                <action android:name="android.intent.action.MAIN" />

                 android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         android:name=".IntroActivity"/>
    

slide_layout.xml

xml version="1.0" encoding="utf-8"?>

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    
        android:id="@+id/imageView"
        android:layout_width="233dp"
        android:layout_height="283dp"
        android:layout_above="@+id/slide_judul"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="122dp"
        android:layout_marginBottom="18dp"
        app:srcCompat="@drawable/slide_1" />

    
        android:id="@+id/slide_judul"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"

        android:layout_marginStart="150dp"
        android:layout_marginEnd="150dp"
        android:layout_marginBottom="298dp"
        android:fontFamily="sans-serif-black"
        android:textStyle="bold"
        android:textSize="25dp"
        android:textAlignment="center"
        android:textColor="@color/colorWhite"
        android:text="SIMPLE" />

   <TextView
        android:id="@+id/slideDeskripsi"
        android:layout_width="323dp"
        android:layout_height="wrap_content"

        android:layout_alignTop="@+id/slide_judul"

        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"


        android:layout_marginStart="35dp"
        android:layout_marginTop="50dp"
        android:layout_marginEnd="35dp"
        android:layout_marginBottom="-109dp"
        android:textColor="@color/colorWhite"
        android:fontFamily="sans-serif-smallcaps"
        android:text="Belajar dengan mudah dan cepat mengerti menggunakan metode yang simple"
        android:textAlignment="center"
        android:textSize="20dp" />


activity_intro.xml

xml version="1.0" encoding="utf-8"?>

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    
        android:id="@+id/imageView"
        android:layout_width="233dp"
        android:layout_height="283dp"
        android:layout_above="@+id/slide_judul"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="122dp"
        android:layout_marginBottom="18dp"
        app:srcCompat="@drawable/slide_1" />

    
        android:id="@+id/slide_judul"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"

        android:layout_marginStart="150dp"
        android:layout_marginEnd="150dp"
        android:layout_marginBottom="298dp"
        android:fontFamily="sans-serif-black"
        android:textStyle="bold"
        android:textSize="25dp"
        android:textAlignment="center"
        android:textColor="@color/colorWhite"
        android:text="SIMPLE" />

    <TextView
        android:id="@+id/slideDeskripsi"
        android:layout_width="323dp"
        android:layout_height="wrap_content"

        android:layout_alignTop="@+id/slide_judul"

        android:layout_alignParentStart="true"
        android:layout_alignParentEnd="true"


        android:layout_marginStart="35dp"
        android:layout_marginTop="50dp"
        android:layout_marginEnd="35dp"
        android:layout_marginBottom="-109dp"
        android:textColor="@color/colorWhite"
        android:fontFamily="sans-serif-smallcaps"
        android:text="Belajar dengan mudah dan cepat mengerti menggunakan metode yang simple"
        android:textAlignment="center"
        android:textSize="20dp" />


acivity_main.xml


xml version="1.0" encoding="utf-8"?>
 xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Hello World" />



Download This File (Click All , Right Click and Save As Picture)
- Background
- Slide 1
- Slide 2
- Slide 3

And Paste To Folder /res/drawable


SlideAdapter.java

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SlideAdapter extends PagerAdapter {

    Context context;
    LayoutInflater layoutInflater;

    public SlideAdapter (Context context) {
        this.context = context;
    }
    public int[] slide_image = {
            R.drawable.slide_1,
            R.drawable.slide_2,
            R.drawable.slide_3
    };
    public  String [] judul_slide = {
            "SIMPLE",
            "MUDAH",
            "EFISIEN"
    };
    public  String[] desc_slide = {
            "Eitss... Kata siapa belajar bahasa pemprograman itu rumit ? Disini kami akan membuat kamu belajarnya makin simple gak ada lagi deh ungkapan rumit.",
            "Bahasa Pemprograman itu Sulit ? Enggak Juga kok , Disini kami akan membantu kamu dalam belajar menjadi Mudah.",
            "EFISIEN ? Yaps .... Disini kami membuat aplikasi mobile yang dapat membantu kamu dalam belajar dimanapun kamu berada !"
    };
    @Override
    public int getCount() {
        return judul_slide.length;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == (RelativeLayout) o;
    }

    public Object instantiateItem(ViewGroup container , int position) {
        layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        View view = layoutInflater.inflate(R.layout.slide_layout,container,false);
        ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
        TextView judulSlide = (TextView) view.findViewById(R.id.slide_judul);
        TextView descSlide = (TextView) view.findViewById(R.id.slideDeskripsi);

        imageView.setImageResource(slide_image[position]);
        judulSlide.setText(judul_slide[position]);
        descSlide.setText(desc_slide[position]);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((RelativeLayout)object);
    }
}

IntroActivity.java

import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.ViewDebug;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import static java.security.AccessController.getContext;

public class IntroActivity extends AppCompatActivity {
    public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
public static final String COMPLETED_ONBOARDING_PREF_NAME = "Onboarding Completed";
private ViewPager mSlideViewPager;
private LinearLayout mDotLayout;
private  SlideAdapter slideAdapter;
private TextView[] mDot;
private Button prevBtn,NextBtn;
private int mCurrentPage;
private SharedPreferences MyOnboardingFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intro);


        mSlideViewPager = (ViewPager) findViewById(R.id.slideView);
        mDotLayout = (LinearLayout) findViewById(R.id.dot);
        prevBtn = (Button) findViewById(R.id.prev);
        NextBtn = (Button) findViewById(R.id.next);
        slideAdapter = new SlideAdapter(this);
        mSlideViewPager.setAdapter(slideAdapter);
        addDotsIndicator(0);
        mSlideViewPager.addOnPageChangeListener(viewListener);

        //Function Button
        NextBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                mSlideViewPager.setCurrentItem(mCurrentPage + 1);

                if (NextBtn.getText().toString().equals("Finish")) {

                    SharedPreferences.Editor sharedPreferencesEditor =
                            PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
                    sharedPreferencesEditor.putBoolean(
                            COMPLETED_ONBOARDING_PREF_NAME, true);
                    sharedPreferencesEditor.apply();
                    finish();
                    Toast.makeText(IntroActivity.this , "Sukses", Toast.LENGTH_LONG).show();
                    startActivity(new Intent(IntroActivity.this, MainActivity.class));

                }

            }
        });
        //Function Button
        prevBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                mSlideViewPager.setCurrentItem(mCurrentPage - 1);
            }
        });


    }

    public void addDotsIndicator( int position) {
        mDot = new TextView [3];
        mDotLayout.removeAllViews();
        for(int i = 0; i<mDot.length; i++) {
            mDot[i] = new TextView(this);
            mDot[i].setText(Html.fromHtml("&#8226"));
            mDot[i].setTextSize(35);
            mDot[i].setTextColor(getResources().getColor(R.color.colorTransparentWhite));
            mDotLayout.addView(mDot[i]);

        }
        if (mDot.length > 0) {
            mDot[position].setTextColor(getResources().getColor(R.color.colorWhite));

        }
    }
    ViewPager.OnPageChangeListener viewListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int i, float v, int i1) {

        }

        @Override
        public void onPageSelected(int i) {
        addDotsIndicator(i);
        mCurrentPage = i;

        if(i==0) {
            NextBtn.setEnabled(true);
            prevBtn.setEnabled(false);
            prevBtn.setVisibility(View.INVISIBLE);

            NextBtn.setText("Next");
            prevBtn.setText("");
        } else if (i == mDot.length -1) {
            NextBtn.setEnabled(true);
            prevBtn.setEnabled(true);
            prevBtn.setVisibility(View.VISIBLE);

            NextBtn.setText("Finish");
            prevBtn.setText("Back");
        } else {
            NextBtn.setEnabled(true);
            prevBtn.setEnabled(true);
            prevBtn.setVisibility(View.VISIBLE);

            NextBtn.setText("Next");
            prevBtn.setText("Back");
        }
        }

        @Override
        public void onPageScrollStateChanged(int i) {

        }
    };


}

MainActivity.java

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SharedPreferences sharedPreferences =
                PreferenceManager.getDefaultSharedPreferences(this);
        // Check if we need to display our OnboardingFragment
        if (!sharedPreferences.getBoolean(
                IntroActivity.COMPLETED_ONBOARDING_PREF_NAME, false)) {
            // The user hasn't seen the OnboardingFragment yet, so show it
            startActivity(new Intent(this, IntroActivity.class));
        }

    }

}

Test And Run ;D

Thanks To :
- Alam Semesta
- Google
- TVAC Studio
- Modifer & Add Feature By @RonnyLiem.ID

Subscribe Untuk Mendapatkan Info Terbaru Dari Kami Lewat Email:

Tidak Ada Tanggapan Untuk "How To Make The First Slide Intro After Installation - Android Studio (Java)"

Post a Comment