WelcomeScreen in Android || Custom Welcome Screen in ANdroid...
in Main Xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
android:weightSum="1"
tools:context=".activities.Introduction">
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_weight="0.8"
android:layout_width="match_parent"
android:layout_height="0dp">
</androidx.viewpager.widget.ViewPager>
<LinearLayout
android:layout_weight="0.2"
android:layout_width="match_parent"
android:orientation="horizontal"
android:weightSum="1"
android:layout_height="0dp" >
<Button
android:visibility="invisible"
android:layout_width="0dp"
android:textColor="@color/white"
android:background="@color/Green"
android:text="Get Started"
android:layout_height="40dp"
android:layout_weight=".1"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLay"
android:paddingVertical="10dp"
android:paddingHorizontal="10dp"
android:layout_gravity="center_vertical"
app:tabBackground="@drawable/indicator_selector"
android:layout_weight=".3"
android:layout_width="0dp"
android:layout_height="40dp"
>
</com.google.android.material.tabs.TabLayout>
<Button
android:layout_marginTop="20dp"
android:id="@+id/btnGet"
android:visibility="invisible"
android:layout_width="0dp"
android:textColor="@color/white"
android:background="@color/Green"
android:text="Get Started"
android:layout_height="40dp"
android:layout_weight=".4"/>
<Button
android:id="@+id/BtnNext"
android:layout_gravity="center_vertical"
android:text="@string/next"
android:layout_weight=".2"
android:background="@color/transparent"
android:layout_width="60dp"
android:layout_height="50dp"
>
</Button>
</LinearLayout>
</LinearLayout>
in custom layout..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<Button
android:layout_margin="10dp"
android:id="@+id/skip"
android:layout_gravity="right"
android:background="@color/transparent"
android:text="Skip"
android:textAllCaps="false"
android:textColor="@color/yellow"
android:layout_width="55dp"
android:layout_height="50dp"
android:textSize="14sp">
</Button>
<ImageView
android:id="@+id/imgHeader"
android:layout_marginTop="80dp"
android:layout_gravity="center_horizontal"
android:layout_width="300dp"
android:layout_height="300dp"
android:src="@drawable/man"
>
</ImageView>
<TextView
android:layout_marginVertical="10dp"
android:id="@+id/txtTitle"
android:gravity="center"
android:textSize="28sp"
android:textStyle="bold"
android:textColor="@color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
>
</TextView>
<TextView
android:layout_marginVertical="10dp"
android:id="@+id/txtSubT"
android:gravity="center"
android:textSize="14sp"
android:textStyle="italic|normal"
android:textColor="@color/grey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
>
</TextView>
</LinearLayout>
then create Adapter
package com.daizzyinfo.test.adapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import com.daizzyinfo.test.R;
import com.daizzyinfo.test.activities.BottomNavigation;
import com.daizzyinfo.test.model.ModelIntro;
import java.util.List;
public class IntroAdapter extends PagerAdapter {
Context mCtx;
List<ModelIntro> modelIntro;
public IntroAdapter(Context mCtx, List<ModelIntro> modelIntro) {
this.mCtx = mCtx;
this.modelIntro = modelIntro;
}
@NonNull
@Override @SuppressLint("MissingInflatedId")
public Object instantiateItem(@NonNull ViewGroup container, int position) {
LayoutInflater inflater = (LayoutInflater) mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.layout_screen,null );
ImageView imgHeader =view.findViewById(R.id.imgHeader);
TextView txtTitle = view.findViewById(R.id.txtTitle);
TextView txtSubT = view.findViewById(R.id.txtSubT);
Button skip = view.findViewById(R.id.skip);
imgHeader.setImageResource(modelIntro.get(position).getHeadImg());
txtTitle.setText(modelIntro.get(position).getTitle());
txtSubT.setText(modelIntro.get(position).getDescription());
container.addView(view);
skip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(mCtx,BottomNavigation.class);
mCtx.startActivity(i);
}
});
return view;
}
@Override
public int getCount() {
return modelIntro.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
}
then Model Class.
package com.daizzyinfo.test.model;
public class ModelIntro {
String description,title;
int HeadImg;
public ModelIntro(String description, String title, int headImg) {
this.description = description;
this.title = title;
HeadImg = headImg;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getHeadImg() {
return HeadImg;
}
public void setHeadImg(int headImg) {
HeadImg = headImg;
}
}
then go to Main Activity..
package com.daizzyinfo.test.activities;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.daizzyinfo.test.R;
import com.daizzyinfo.test.adapter.IntroAdapter;
import com.daizzyinfo.test.model.ModelIntro;
import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import java.util.List;
public class Introduction extends AppCompatActivity {
ViewPager viewPager;
TabLayout tabLay;
Button BtnNext,btnGet;
List<ModelIntro> mList = new ArrayList<>();
int position = 0;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_introduction);
viewPager=findViewById(R.id.viewPager);
tabLay=findViewById(R.id.tabLay);
BtnNext=findViewById(R.id.BtnNext);
btnGet=findViewById(R.id.btnGet);
mList.add(new ModelIntro("Reference site about Lorem\nIpsum, giving information on its origins, as ","Hello Good Food's \n Fast Delivery" ,R.drawable.img1));
mList.add(new ModelIntro("Reference site about Lorem\nIpsum, giving information on its origins, as ","Hello Good Food's \n Fast Delivery",R.drawable.img2));
mList.add(new ModelIntro("Reference site about Lorem\nIpsum, giving information on its origins, as ","Hello Good Food's \n Fast Delivery" ,R.drawable.img3));
IntroAdapter adapter = new IntroAdapter(this,mList);
viewPager.setAdapter(adapter);
tabLay.setupWithViewPager(viewPager);
BtnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
position = viewPager.getCurrentItem();
if(position < mList.size())
{
position++;
viewPager.setCurrentItem(position);
}
if(position == mList.size()-1)
{
loadLastScreen();
}
}
});
tabLay.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
if(tab.getPosition() == mList.size()-1)
{
loadLastScreen();
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
btnGet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),BottomNavigation.class);
startActivity(i);
finishAffinity();
}
});
}
protected void loadLastScreen(){
btnGet.setVisibility(View.VISIBLE);
BtnNext.setVisibility(View.INVISIBLE);
tabLay.setVisibility(View.INVISIBLE);
}
}
Comments
Post a Comment