tabhost取消默认的白底色

http://www.cnblogs.com/zhaolong_chn/archive/2011/12/18/2291872.html
http://www.cnblogs.com/wader2011/archive/2011/10/13/2209668.html
http://www.cnblogs.com/zhukoo/archive/2011/09/30/2196878.html

package com.hg.beyond.demo.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

import com.hg.beyond.demo.R;

public class PhoneManagerHomeActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.phone_manager_home);
setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
launchTabHost();
}

private void launchTabHost() {

final TabHost tabHost = this.getTabHost();


//注册监听器调用方法改变底色
tabHost.setOnTabChangedListener(new OnTabChangeListener() {

@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
updateTabBackground(tabHost);

}
});
View callView = LayoutInflater.from(this).inflate(
R.layout.phone_manager_tab_item, null);

View msgView = LayoutInflater.from(this).inflate(
R.layout.phone_manager_tab_item, null);

View contactView = LayoutInflater.from(this).inflate(
R.layout.phone_manager_tab_item, null);

View favoritView = LayoutInflater.from(this).inflate(
R.layout.phone_manager_tab_item, null);

TextView callLable = (TextView) callView
.findViewById(R.id.tab_item_lable);
ImageView callImage = (ImageView) callView
.findViewById(R.id.tab_item_icon);
callLable.setText(getString(R.string.tab_call_txt));
callImage.setImageResource(R.drawable.call_tab_item_selector);

TextView contactLable = (TextView) contactView
.findViewById(R.id.tab_item_lable);
ImageView contactImage = (ImageView) contactView
.findViewById(R.id.tab_item_icon);
contactLable.setText(getString(R.string.tab_contact_txt));
contactImage.setImageResource(R.drawable.contact_tab_item_selector);

TextView msgLable = (TextView) msgView
.findViewById(R.id.tab_item_lable);
ImageView msgImage = (ImageView) msgView
.findViewById(R.id.tab_item_icon);
msgLable.setText(getString(R.string.tab_msg_txt));
msgImage.setImageResource(R.drawable.msg_tab_item_selector);

TextView favoritLable = (TextView) favoritView
.findViewById(R.id.tab_item_lable);
ImageView favoritImage = (ImageView) favoritView
.findViewById(R.id.tab_item_icon);
favoritLable.setText(getString(R.string.tab_fav_txt));
favoritImage.setImageResource(R.drawable.fav_tab_item_selector);

tabHost.addTab(tabHost.newTabSpec("call").setIndicator(callView)
.setContent(new Intent(this, CallActivity.class)));

tabHost.addTab(tabHost.newTabSpec("msg").setIndicator(msgView)
.setContent(new Intent(this, MsgActivity.class)));

tabHost.addTab(tabHost.newTabSpec("contact").setIndicator(contactView)
.setContent(new Intent(this, ContactActivity.class)));

tabHost.addTab(tabHost.newTabSpec("favorit").setIndicator(favoritView)
.setContent(new Intent(this, FavoritActivity.class)));
tabHost.setCurrentTab(0);
}

/**
* 更新Tab标签的底色图
*
* @param tabHost
*/
private void updateTabBackground(final TabHost tabHost) {
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
View vvv = tabHost.getTabWidget().getChildAt(i);
if (tabHost.getCurrentTab() == i) {

// 选中后的背景
vvv.setBackgroundDrawable(getResources().getDrawable(
R.drawable.cm_tabwidget_select_bg));
} else {
// 非选择的背景
vvv.setBackgroundDrawable(null);
}
}
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值