【Android】通过Java代码替换TabHost中的drawableTop资源
来源:互联网 发布:sql语句select空 编辑:程序博客网 时间:2024/05/16 13:40
在博客 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);}}});从而可以得到想要的切换效果。
- 【Android】通过Java代码替换TabHost中的drawableTop资源
- android 怎么代码控制 drawableTop
- android在代码中设置drawableTop属性
- Android TabHost+Fragment替换TabActivity
- Android “fragment” 替换 “Tabhost”技术
- Android中的TabHost
- Android中的TabHost
- Android中的TabHost
- Android中的TabHost
- Android中的TabHost
- Android中的TabHost
- java 代码中实现 TextView的 DrawableTop属性
- android webView中的html页面通过javascript访问java代码
- Android资源文件在配置文件中的使用与java代码对资源文件的操作
- android中java代码中通过资源id加载String方法
- android替换apk中的资源图片后重新签名流程
- 通过按键控制ListView,TabHost中的焦点。
- Android设置drawableTop图片大小
- 计算机为什么要用补码存储整型
- 强悍的ptrace——进程追踪,系统调用能手
- leetcode_question_129 Sum Root to Leaf Numbers
- Shell 中的算术计算
- 中国手机网络制式常识
- 【Android】通过Java代码替换TabHost中的drawableTop资源
- CERT关于Java安全编码规范的新书
- 11.2.0.4 Patch Set - List of Bug Fixes by Problem Type (Doc ID 1562142.1)
- POJ 2328每日一水
- BIOS跟Ubuntu无关
- UVa 102 Ecological Bin Packing (water ver.)
- IP层协议 以及 ARP RARP.
- 完全二叉树指向同一层的相邻结点
- find 的使用