读书人

tabhost撤销默认的白底色

发布时间: 2012-07-01 13:15:00 作者: rapoo

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 {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.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() {@Overridepublic void onTabChanged(String tabId) {// TODO Auto-generated method stubupdateTabBackground(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);}}}}

读书人网 >操作系统

热点推荐