<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/teal_700"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView5"
android:layout_width="50dp"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:src="@mipmap/ic_launcher_round"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="sans-serif-smallcaps"
android:gravity="center_vertical"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="Wp Status Downloader"
android:textColor="@android:color/white"
android:textSize="18dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/shareBtn"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/imageView5"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@+id/shareBtn"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
android:paddingTop="10dp"
android:paddingBottom="5dp"
android:src="@drawable/ic_baseline_share_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
</LinearLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout3">
<com.google.android.material.tabs.TabItem
android:id="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/ic_baseline_image_24" />
<com.google.android.material.tabs.TabItem
android:id="@+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/ic_baseline_video_library_24" />
<com.google.android.material.tabs.TabItem
android:id="@+id/tab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/ic_baseline_cloud_download_24" />
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_constraintBottom_toTopOf="@+id/banner_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tabLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
Create A Java Class named "PageAdapter" by Right Click on app>new>java class
code..
public class PageAdapter extends FragmentPagerAdapter {
int tabCount;
public PageAdapter(@NonNull FragmentManager fm, int behavior) {
super(fm, behavior);
tabCount=behavior;
}
@NonNull
@Override
public Fragment getItem(int position) {
switch (position){
case 0: return new ImageFragment();
case 1: return new VideoFragment();
case 2: return new GallaryFragment();
default: return null;
}
}
@Override
public int getCount() {
return tabCount;
}
}
MainActivit.java :
public class MainActivity extends AppCompatActivity {
private TabLayout tabLayout;
private TabItem tab1,tab2,tab3;
private ViewPager viewPager;
private int taPosition =0;
private PagerAdapter pagerAdapter;
private ImageView shareBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
pagerAdapter= new PageAdapter(getSupportFragmentManager(),tabLayout.getTabCount());
viewPager.setAdapter(pagerAdapter);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
if (tab.getPosition() == 0 || tab.getPosition() ==1 || tab.getPosition() ==2){
pagerAdapter.notifyDataSetChanged();
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
shareBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String textS= "https://play.google.com/store/apps/details?id=com.magica_technology.wpstatusdownloder";
Intent shareIntent= ShareCompat.IntentBuilder.from(MainActivity.this)
.setText(textS)
.setType("text/*")
.setChooserTitle("WS Downloader")
.getIntent();
if (shareIntent.resolveActivity(getPackageManager())!= null){
startActivity(shareIntent);
}
}
});
}
private void init() {
tabLayout=findViewById(R.id.tabLayout);
tab1=findViewById(R.id.tab1);
tab2=findViewById(R.id.tab2);
tab3=findViewById(R.id.tab3);
viewPager=findViewById(R.id.viewPager);
shareBtn=findViewById(R.id.shareBtn);
}
}