zoukankan      html  css  js  c++  java
  • 【Android】通过Java代码替换TabHost中的drawableTop资源

    在博客 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);
    						}
    					}
    				});

    从而可以得到想要的切换效果。

  • 相关阅读:
    ArrayList集合 、特殊集合
    二维数组 、多维数组
    一维数组
    类:String,Math,DateTime,Random
    while做法1.兔子生兔子 2.求100以内质数的和3.洗发水15元 牙膏5元 香皂2元 150元的算法
    博客迁移
    [WC2008]游览计划 「斯坦那树模板」
    [SDOI2009]HH去散步 「矩阵乘法计数」
    [HNOI2007]梦幻岛宝珠 「套路:分层 $DP$」
    多项式求逆
  • 原文地址:https://www.cnblogs.com/james1207/p/3331301.html
Copyright © 2011-2022 走看看