在博客http://blog.csdn.net/jueblog/article/details/11837445中的Tab选项卡中,
点击相应的Tab选项,图标没有发生改变。
这些资源图片也没有尽用,若要使点击选项后,图标发生改变,可以在Java代码中实现。
改变drawableTop的Java代码:
tab_icon_weixin.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_weixin_pressed,0, 0);
从而,我们可以对Tab代码进行优化:
main_radio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int id) {
if (id == tab_icon_weixin.getId()) {
tab_icon_weixin.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_weixin_pressed,0, 0);
tab_icon_address.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_address_normal,0, 0);
tab_icon_find.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_find_frd_normal,0, 0);
tab_icon_myself.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_settings_normal,0, 0);
mTabHost.setCurrentTab(0);
} else if (id == tab_icon_address.getId()) {
tab_icon_weixin.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_weixin_normal,0, 0);
tab_icon_address.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_address_pressed,0, 0);
tab_icon_find.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_find_frd_normal,0, 0);
tab_icon_myself.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_settings_normal,0, 0);
mTabHost.setCurrentTab(1);
} else if (id == tab_icon_find.getId()) {
tab_icon_weixin.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_weixin_normal,0, 0);
tab_icon_address.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_address_normal,0, 0);
tab_icon_find.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_find_frd_pressed,0, 0);
tab_icon_myself.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_settings_normal,0, 0);
mTabHost.setCurrentTab(2);
} else if (id == tab_icon_myself.getId()) {
tab_icon_weixin.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_weixin_normal,0, 0);
tab_icon_address.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_address_normal,0, 0);
tab_icon_find.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_find_frd_normal,0, 0);
tab_icon_myself.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_settings_pressed,0, 0);
mTabHost.setCurrentTab(3);
}
}
});
从而可以得到想要的切换效果。
分享到:
相关推荐
Android TabHost ListView初学者的实例代码
Android实现tabHost控件自定义页签页面源码
安卓Android源码——ViewPager和Tabhost结合,可滑动的tabhost.rar
Android 嵌套TabHost示例. 两层TabHost嵌套,实现的效果类似网页上的二级菜单栏。
安卓Android源码——ViewPager和Tabhost结合,可滑动的tabhost.zip
利用Tabhost + Fragment实现android标签切换界面.
androidTabhost的使用实例代码,仅供参考
tabhost--UI源码.zip
设置Android自带id : XML布局文件中, 可以使用 标签设置, 其中的id 需要引用 android的自带id : android:id=@android:id/tabhost ; getHost()获取前提 : 设置了该id之后, 在Activity界面可以使用 getHost(), 获取...
TabHostActivity在API 13之后就不能用了。 写了个Demo,用FragmentActivity + Tabhost实现多标签页,并添加滑动手势。 API=19,可运行
TabHost的使用方法,适合初学者,适合课堂讲授实现模拟显示未接来电、已接来电和拨出电话的选项卡。
Android编程之Intent_TabHost源码演示,自定义的Tabhost(内含源码),学习制作Android软件的TAB标签界面,在电脑上已经很流行的功能,Android手机上当然不能少,这个TabHost源码相对简单些,是JAVA转学Android比较...
TabHost中填充自定义ListView
最近在使用TabHost的时候遇到了一些奇怪的问题,在这里总结分享备忘一下。
Android Tabhost 实例demo 自定义Tabhost实现实例。
android通过tabhost实现标签页
android Tabhost使用Demo
解决ViewGroup中使用TabHost时tabhost中的tab不能显示的问题
tabhost中嵌套一个tabhost。
Android fragment 内部嵌套tabhost组件 详情请见: http://blog.csdn.net/singleton1900/article/details/27087833