去掉TabActivity底部默认白线

阅读更多
经过一翻百度,google终于实现了TabActivity设置tab自定义背景颜色,设置tab中标题文字的颜色。并将TabWidget置于底部

去掉TabActivity底部默认白线_第1张图片

TabManager:
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;

public class TabManager extends TabActivity{
	private TabManager th;
	private TabHost tabHost;
	private TabWidget tabWidget;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tab_content);
		th = this;
		 tabHost = (TabHost) findViewById(android.R.id.tabhost);
		 LayoutInflater.from(this).inflate(R.layout.main,tabHost.getTabContentView(),true);
		 tabWidget = tabHost.getTabWidget();
		 tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Tab1",th.getResources().getDrawable(R.drawable.ic_menu_home_tab))
				  .setContent(new Intent(this, Tab1.class)));
		 tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tab2",th.getResources().getDrawable(R.drawable.ic_menu_camera_tab))
				 .setContent(new Intent(this, Tab2.class)));
		 tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Tab3",th.getResources().getDrawable(R.drawable.ic_menu_search_tab))
				 .setContent(new Intent(this, Tab3.class)));
		 tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator("Tab4",th.getResources().getDrawable(R.drawable.ic_menu_upload_tab))
				 .setContent(new Intent(this, Tab4.class)));
		 tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("Tab5",th.getResources().getDrawable(R.drawable.ic_menu_preferences_tab))
				 .setContent(new Intent(this, Tab5.class)));
		  tabHost.setCurrentTab(0);

		for (int i = 0; i < tabWidget.getChildCount(); i++) {
			/**
			 * 此方法是为了去掉系统默认的色白的底角
			 */
			tabHost.setPadding(tabHost.getPaddingLeft(), tabHost.getPaddingTop(), tabHost.getPaddingRight(), tabHost.getPaddingBottom() - 5);
			View v = tabWidget.getChildAt(i);
			//设置tab背景颜色
			v.setBackgroundResource(R.drawable.tab_indicator);
			
			//设置tab中标题文字的颜色,不然默认为黑色
	        XmlResourceParser xpp = getResources().getXml(R.color.tab_font_selector); 
	        try {
	        	ColorStateList csl= ColorStateList.createFromXml(getResources(),xpp);
	        	TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
	 	        tv.setTextColor(csl);
	        } catch (Exception e){
	        	e.printStackTrace();
	        }
		}
	}
}


tab_indicator.xml:


	
	
	

	
	
	

	
	


tab_font_selector.xml:


	
	
	

	
	
	

	
	


colors.xml:



	#ff000000
	#ff383838
	#ffff8000
	#ffe9a700

	#ff888888
	#ffffffff
	#ffffffff
	#ff888888

	#FF000000
	#FF444444
	#FF888888
	#FFCCCCCC
	#FFFFFFFF
	#FFFF0000
	#FF00FF00
	#FF0000FF
	#FFFFFF00
	#FF00FFFF
	#FFFF00FF
	#00000000


转自:http://www.cmd100.com/bbs/thread-156307-1-1.html
  • 去掉TabActivity底部默认白线_第2张图片
  • 大小: 13.3 KB
  • zdy_tab.rar (79.9 KB)
  • 下载次数: 167
  • 查看图片附件

你可能感兴趣的:(android,tabActivity,底部白线)