微信Tab页


 

 

参考开源项目PagerSlidingTabStrip

做了一些小修改,比如设置Tab页平均铺满效果、字体变色等 微调的代码请 下载

关于我


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private void addTab(final int position, View tab) {
    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });
     
    tab.setPadding(tabPadding, 0, tabPadding, 0);
    setShouldExpand(true);//设置weight=1.0f,实现平铺的效果,add by lichen
    if (tab instanceof TextView) {
        if (position == 0) {//默认首项字体颜色,add by lichen
            ((TextView) tab).setTextColor(getResources().getColor(R.color.deep_green));
        } else {//其他项字体颜色,add by lichen
            ((TextView) tab).setTextColor(getResources().getColor(R.color.light_green));
        }
    }
    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
        @Override
        public void onPageSelected(int position) {
            View view = tabsContainer.getChildAt(position);
            if (view instanceof ImageButton) {//如果是图片是Tab页,add by lichen
                ((ImageButton) view).setImageResource(R.drawable.ic_input_add);
            } else if (view instanceof TextView) {
                setColor(position);
            }
            if (delegatePageListener != null) {
                delegatePageListener.onPageSelected(position);
            }
        }
 
/**
 * 滑动tab修改字体颜色,by lichen
 * @param position
 */
private void setColor(int position) {
    TextView textView0 = (TextView) tabsContainer.getChildAt(0);
    TextView textView1 = (TextView) tabsContainer.getChildAt(1);
    TextView textView2 = (TextView) tabsContainer.getChildAt(2);
    switch (position) {
    case 0:
        textView0.setTextColor(getResources().getColor(R.color.deep_green));
        textView1.setTextColor(getResources().getColor(R.color.light_green));
        textView2.setTextColor(getResources().getColor(R.color.light_green));
        break;
    case 1:
        textView0.setTextColor(getResources().getColor(R.color.light_green));
        textView1.setTextColor(getResources().getColor(R.color.deep_green));
        textView2.setTextColor(getResources().getColor(R.color.light_green));
        break;
    case 2:
        textView0.setTextColor(getResources().getColor(R.color.light_green));
        textView1.setTextColor(getResources().getColor(R.color.light_green));
        textView2.setTextColor(getResources().getColor(R.color.deep_green));
        break;
    default:
        break;
    }
}

 

转载于:https://my.oschina.net/lichen/blog/267220

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值