iv_image1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
veb.setCurrentItem(0);
}
});
iv_image2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
veb.setCurrentItem(1);
}
});
iv_image3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
veb.setCurrentItem(2);
}
});
tv_sy.setTextColor(Color.GREEN);
iv_image1.setImageResource(R.drawable.tab_main_select);
veb.setAdapter(new Addapter(getSupportFragmentManager()));
veb.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
switch (position)
{
case 0:
tv_sy.setTextColor(Color.GREEN);
iv_image1.setImageResource(R.drawable.tab_main_select);
tv_gn.setTextColor(Color.BLACK);
iv_image2.setImageResource(R.drawable.tab_category_normal);
tv_wd.setTextColor(Color.BLACK);
iv_image3.setImageResource(R.drawable.tab_me_normal);
break;
case 1:
tv_sy.setTextColor(Color.BLACK);
iv_image1.setImageResource(R.drawable.tab_main_normal);
tv_gn.setTextColor(Color.GREEN);
iv_image2.setImageResource(R.drawable.tab_catefory_select);
tv_wd.setTextColor(Color.BLACK);
iv_image3.setImageResource(R.drawable.tab_me_normal);
break;
case 2:
tv_sy.setTextColor(Color.BLACK);
iv_image1.setImageResource(R.drawable.tab_main_normal);
tv_gn.setTextColor(Color.BLACK);
iv_image2.setImageResource(R.drawable.tab_category_normal);
tv_wd.setTextColor(Color.GREEN);
iv_image3.setImageResource(R.drawable.tab_me_select);
break;
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
private void initView() {
veb = findViewById(R.id.veb);
iv_image1=findViewById(R.id.iv_image1);
tv_sy=findViewById(R.id.tv_sy);
iv_image2=findViewById(R.id.iv_image2);
tv_gn=findViewById(R.id.tv_gn);
iv_image3=findViewById(R.id.iv_image3);
tv_wd=findViewById(R.id.tv_wd);
}
class Addapter extends FragmentPagerAdapter
{
public Addapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
Fragment fragment=null;
switch (position) {
case 0:
fragment=new Fragment1();
break;
case 1:
fragment=new Fragment2();
break;
case 2:
fragment=new Fragment3();
break;
}
return fragment;
}
@Override
public int getCount() {
return 3;
}
}
}