您的位置:首页 > 移动开发 > Android开发

Android左右切换的标签

2016-06-29 10:42 573 查看
/**
* 创建框架,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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  标签 tabhost