首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

增多tab提示效果

2012-09-29 
增加tab提示效果先说一下需求,我有多个tab页,每个tab也有新数据时我要动态提示是那个tab页收到了新数据。我

增加tab提示效果
先说一下需求,我有多个tab页,每个tab也有新数据时我要动态提示是那个tab页收到了新数据。
我采用的继承TabActivity然后用
.addTab(myTabhost.newTabSpec("Sex")// make a new Tab
.setIndicator("首页",getResources().getDrawable(R.drawable.a_1))
// set the Title and Icon
.setContent(new Intent(this,HomeActivity.class)));
然后我采用的是线程来控制,改变tab页text的颜色
private TabHost myTabhost;
private final int START=1;
private Message msg;
private TextView tv;
new Thread(new Runnable() {
        @Override
            public void run() {
            while(true){
              try {
                    msg = Message.obtain();
                     msg.what = 1;
                     handler.sendMessage(msg);
                           Thread.sleep(500);
//不停切换
                    } catch (InterruptedException e) {
                }
            }
            }
        }).start();
private final Handler handler = new Handler() {

public void handleMessage(Message msg) {
super.handleMessage(msg);

switch (msg.what) {
case START:
TabHost host=getTabHost();
TabWidget  widget=host.getTabWidget();
  tv = (TextView) widget.getChildAt(2).findViewById(android.R.id.title);//这儿getChildAt(2)是选择的第三个tab页进行提示,这儿可以动态给值
String r=decToHex((int)Math.floor(Math.random()*256)-1);
String g=decToHex((int)Math.floor(Math.random()*256)-1);
String b=decToHex((int)Math.floor(Math.random()*256)-1);
  tv.setTextColor(Color.parseColor("#"+r+g+b));
break;
}
}

};
public String decToHex(int dec)   
{   
String hexStr = "0123456789ABCDEF";   
int low = Math.abs(dec % 16);   
int high = Math.abs((dec - low)/16);   
String hex = "" + (hexStr.length()>high?hexStr.charAt(high):hexStr.charAt(0)) + (hexStr.length()>low?hexStr.charAt(low):hexStr.charAt(10));   
return hex;   
}

热点排行