ViewPager+Fragment滑动或者点击导航颜色变化

//主方法implements OnClickListener点击得出下面这个方法
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_one:
vp2.setCurrentItem(0);
tv_one.setTextColor(Color.RED);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.BLACK);
break;
case R.id.tv_two:
vp2.setCurrentItem(1);
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.RED);
tv_three.setTextColor(Color.BLACK);
break;
case R.id.tv_three:
vp2.setCurrentItem(2);
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.RED);
break;



default:
break;
}
}










//设置点击事件
public void tv_onclick(){
tv_one=(TextView) findViewById(R.id.tv_one);
tv_two=(TextView) findViewById(R.id.tv_two);
tv_three=(TextView) findViewById(R.id.tv_three);

tv_one.setTextColor(Color.RED);

tv_one.setOnClickListener(this);
tv_two.setOnClickListener(this);
tv_three.setOnClickListener(this);
}




vp2.setOnPageChangeListener(new OnPageChangeListener() {

@Override
public void onPageSelected(int arg0) {
if(arg0==0){
tv_one.setTextColor(Color.RED);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.BLACK);
}else if(arg0==1){
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.RED);
tv_three.setTextColor(Color.BLACK);
}else if(arg0==2){
tv_one.setTextColor(Color.BLACK);
tv_two.setTextColor(Color.BLACK);
tv_three.setTextColor(Color.RED);
}
}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub

}

@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub

}
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值