各位大侠请自行把代码放到项目中去。没有给的activity自己手写几个。然后替换就可以了 运行不出来的请联系我。
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends ActivityGroup {
public TabHost tab_host;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);
tab_host.setup(this.getLocalActivityManager());
tab_host.setPadding(tab_host.getPaddingLeft(),
tab_host.getPaddingTop(), tab_host.getPaddingRight(),
tab_host.getPaddingBottom()-10);
TabSpec ts1 = tab_host.newTabSpec("TAB_RECOMMEND");
ts1.setIndicator("s", getResources().getDrawable(R.drawable.icon));
ts1.setContent(new Intent(this, TestActivity.class));
tab_host.addTab(ts1);
TabSpec ts2 = tab_host.newTabSpec("TAB_NEWLY");
ts2.setIndicator("s", getResources().getDrawable(R.drawable.icon));
ts2.setContent(new Intent(this, TestActivity.class));
tab_host.addTab(ts2);
TabSpec ts3 = tab_host.newTabSpec("TAB_PHB");
ts3.setIndicator("s", getResources().getDrawable(R.drawable.icon));
ts3.setContent(new Intent(this, TestActivity.class));
tab_host.addTab(ts3);
tab_host.setCurrentTab(0);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="@+id/edit_item_tab_host"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:padding="5dp" android:layout_weight="1" />
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</TabHost>
</LinearLayout>
如果把图片做为按钮 去掉外面黑色的背景 加上
/* 对Tab标签的定制 */
mTabWidget = mTabHost.getTabWidget();
for (int i = 0; i < mTabWidget.getChildCount(); i++)
{
/* 得到每个标签的视图 */
View view = mTabWidget.getChildAt(i);
/* 设置每个标签的背景 */
if (mTabHost.getCurrentTab() == i)
{
if(i==0){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu1));
}else if(i==1){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu3));
}else if(i==2){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu5));
}else if(i==3){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu7));
}
//view.setBackgroundDrawable(getResources().getDrawable(
// R.drawable.home_btn_bg_d));
}
else
{
if(i==0){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu0));
}else if(i==1){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu2));
}else if(i==2){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu4));
}else if(i==3){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu6));
}
//view.setBackgroundDrawable(getResources().getDrawable(
// R.drawable.home_btn_bg_n));
}
/* 设置Tab间分割竖线的颜色 */
// tabWidget.setBackgroundColor(Color.WHITE);
/* 设置Tab间分割竖线的背景图片 */
// tabWidget.setBackgroundResource(R.drawable.icon);
/* 设置tab的高度 */
mTabWidget.getChildAt(i).getLayoutParams().height = 50;
TextView tv = (TextView) mTabWidget.getChildAt(i).findViewById(
android.R.id.title);
tv.setTextSize(18);
/* 设置tab内字体的颜色 */
//tv.setTextColor(Color.rgb(49, 116, 171));
}
/* 当点击Tab选项卡的时候,更改当前Tab标签的背景 */
mTabHost.setOnTabChangedListener(new OnTabChangeListener()
{
@Override
public void onTabChanged(String tabId)
{
for (int i = 0; i < mTabWidget.getChildCount(); i++)
{
View view = mTabWidget.getChildAt(i);
if (mTabHost.getCurrentTab() == i)
{
if(i==0){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu1));
}else if(i==1){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu3));
}else if(i==2){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu5));
}else if(i==3){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu7));
}
//view.setBackgroundDrawable(getResources().getDrawable(
// R.drawable.home_btn_bg_d));
}
else
{
if(i==0){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu0));
}else if(i==1){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu2));
}else if(i==2){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu4));
}else if(i==3){
view.setBackgroundDrawable(getResources().getDrawable(
R.drawable.guide_menu6));
}
//view.setBackgroundDrawable(getResources().getDrawable(
// R.drawable.home_btn_bg_n));
}
}
}
});