TabHost的底部实现

首先在xml文件中做好布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:id="@+id/my_maintabhost"> 
    <TabHost 
        android:id="@+id/tabhost" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 
        <FrameLayout 
            android:id="@android:id/tabcontent" 
            android:layout_width="match_parent" 
            android:layout_height="match_parent" 
            android:paddingBottom="55px"> 
        </FrameLayout> 
        <RelativeLayout 
            android:layout_width="match_parent" 
            android:layout_height="match_parent"> 
            <TabWidget 
                android:id="@android:id/tab1" 
                android:layout_alignParentBottom="true" 
                android:layout_width="match_parent" 
                android:layout_height="50px" /> 
        </RelativeLayout> 
    </TabHost> 
</LinearLayout> 

再写一个mainActivity里面包含了4个Activity 4个Activity里面各只有一个oncreate还有一个布局的话也是自动生成的一个Textview 这里就不写了

下面就是主要的TabHost

public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


// 取得TabHost
TabHost tabhost = (TabHost) findViewById(R.id.tabhost);
// 设置了TabHost的背景颜色 蓝色
tabhost.setBackgroundColor(Color.argb(150, 20, 80, 150));
tabhost.setup();
LayoutInflater inflater = LayoutInflater.from(this);
// 把配置文件转换为显示TabHost内容的FrameLayout中的层级
inflater.inflate(R.layout.inspection, tabhost.getTabContentView());
inflater.inflate(R.layout.inventory, tabhost.getTabContentView());
inflater.inflate(R.layout.label, tabhost.getTabContentView());
inflater.inflate(R.layout.mytask, tabhost.getTabContentView());
// 设置"任务"标签
TabSpec spec1 = tabhost.newTabSpec("我的任务").setIndicator("我的任务");
// 设置"任务"模块显示内容
spec1.setContent(R.id.my_task);
tabhost.addTab(spec1);


TabSpec spec2 = tabhost.newTabSpec("盘点").setIndicator("盘点");
spec2.setContent(R.id.my_inventory);
tabhost.addTab(spec2);


TabSpec spec3 = tabhost.newTabSpec("巡查").setIndicator("巡查");
spec3.setContent(R.id.my_inspection);
tabhost.addTab(spec3);


TabSpec spec4 = tabhost.newTabSpec("贴标签").setIndicator("贴标签");
spec4.setContent(R.id.my_label);
tabhost.addTab(spec4);
}


private TabHost findViewById(Class<id> class1) {
// TODO Auto-generated method stub
return null;
}
}

这里发下包图

还有效果图

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值