在博客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() {@Overridepublic 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);}}});
从而可以得到想要的切换效果。

更多相关文章

  1. Android培训班(72)Dex文件里类定义dvmDefineClass
  2. Android代码混淆proguard技…
  3. 一段漂亮的Fragment hide,show相关的代码
  4. android 周报 - 2019/10/6-Issue #382
  5. Android Studio 快捷键
  6. Android状态栏通知Status Bar Notification
  7. Android之屏幕方向改变以及onConfigurationChanged事件
  8. 【Android】说做就做:偶的头像华丽的漂浮在map上。。。
  9. Android中如何获取系统中所有的应用程序

随机推荐

  1. android studio运行Kotilin程序出现Error
  2. Android viewpage滑动选项卡
  3. Android实现圆角ImageView
  4. Android Developers:在SQL数据库中保存数
  5. Android创建并更新通知栏通知
  6. 2019 年 Android 面试题汇总
  7. 初学Android,使用菜单资源(十九) .
  8. android usb通信开发
  9. 侧滑栏DrawerLayout的简单使用
  10. android沉浸式+虚拟按键+Fragment+Coordi