Android左右切换的标签

/**
* 创建框架,2个标签
* 1.网络音频
* 2.本地下载
* **/
private void createFrame()
{
TabHost tabHost = this.getTabHost();


//start:这里创建一个网络音频的标签
//创建一个intent,用于跳转到标签对应的activity
Intent networkIntent = new Intent(); 
networkIntent.setClass(MainActivity.this, NetworkActivity.class);
TabHost.TabSpec networkSpec= tabHost.newTabSpec("network");//创建标签页
networkSpec.setIndicator(AppConstant.MainConstant.netTabName);//设置信息显示板,也就是标签的名称
networkSpec.setContent(networkIntent);//设置标签对应的内容
tabHost.addTab(networkSpec);//添加标签
//end

//start:这里创建一个本地下载的标签
Intent localIntent = new Intent();
localIntent.setClass(MainActivity.this, LocalDownActivity.class);
TabHost.TabSpec localSpec=tabHost.newTabSpec("local");
localSpec.setIndicator(AppConstant.MainConstant.localTabName);
localSpec.setContent(localIntent);
tabHost.addTab(localSpec);
//end
设置当前显示哪个标签 
tabHost.setCurrentTab(0);

}




<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
>
<!--用于展示每个标签对应的内容布局,放在前面就是让标签在下方。-->
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
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>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值