tab 转换图片步骤

第一步获取资源图片

Drawable a2=getResources().getDrawable(R.drawable.icon_tab_discovery_normal);

第二步 得到图片大小

a2.setBounds(0, 0,a2.getMinimumWidth(),a2.getMinimumHeight());

第三步改变图片

R1.setCompoundDrawables(null, a2, null, null);

 

1 //得到资源文件
2         a0=getResources().getDrawable(R.drawable.icon_tab_hp_normal);
3         b0=getResources().getDrawable(R.drawable.icon_tab_hp_pressed);
4         a1=getResources().getDrawable(R.drawable.icon_tab_video_normal);
5         b1=getResources().getDrawable(R.drawable.icon_tab_video_pressed);
6         a2=getResources().getDrawable(R.drawable.icon_tab_discovery_normal);
7         b2=getResources().getDrawable(R.drawable.icon_tab_discovery_pressed);
8         a3=getResources().getDrawable(R.drawable.icon_tab_my_normal);
9         b3=getResources().getDrawable(R.drawable.icon_tab_my_pressed);
//设置图片尺寸
1
a0.setBounds(0,0 , a0.getMinimumWidth(), a0.getMinimumHeight()); 2 b0.setBounds(0,0 , b0.getMinimumWidth(), b0.getMinimumHeight()); 3 a1.setBounds(0,0 , a1.getMinimumWidth(), a1.getMinimumHeight()); 4 b1.setBounds(0,0 , b1.getMinimumWidth(), b1.getMinimumHeight()); 5 a2.setBounds(0,0 , a2.getMinimumWidth(), a2.getMinimumHeight()); 6 b2.setBounds(0,0 , b2.getMinimumWidth(), b2.getMinimumHeight()); 7 a3.setBounds(0,0 , a3.getMinimumWidth(), a3.getMinimumHeight()); 8 b3.setBounds(0,0 , b3.getMinimumWidth(), b3.getMinimumHeight());

 

//设置更改的图片
1
R1.setCompoundDrawables(null, a0, null, null); 2 R2.setCompoundDrawables(null, a1, null, null); 3 R3.setCompoundDrawables(null, a2, null, null); 4 R4.setCompoundDrawables(null, a3, null, null);
//设置更改的颜色、
1
R1.setTextColor(getResources().getColor(R.color.bottom)); 2 R2.setTextColor(getResources().getColor(R.color.bottom)); 3 R3.setTextColor(getResources().getColor(R.color.bottom)); 4 R4.setTextColor(getResources().getColor(R.color.bottom));

 

在mainactivity 中已经详细记录

链接:http://pan.baidu.com/s/1o7CJQm2 密码:vbg4

posted @ 2017-02-25 20:38  943987243  阅读(840)  评论(0编辑  收藏  举报