首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

Tab Layout 范例

2012-07-26 
Tab Layout 实例?xml version1.0 encodingutf-8?manifest xmlns:androidhttp://schemas.androi

Tab Layout 实例

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.hyzing"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk android:minSdkVersion="8" />    <application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name" >        <activity            android:name=".HelloTabWidget"            android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <activity            android:name=".AlbumsActivity"            android:label="@string/app_name" >        </activity>        <activity            android:name=".ArtistsActivity"            android:label="@string/app_name" >        </activity>        <activity            android:name=".SongsActivity"            android:label="@string/app_name" >        </activity>    </application></manifest>

?

?

package com.hyzing;import android.app.TabActivity;import android.content.Intent;import android.content.res.Resources;import android.os.Bundle;import android.widget.TabHost;public class HelloTabWidget extends TabActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);     setContentView(R.layout.main);      Resources res = getResources(); // Resource object to get Drawables     TabHost tabHost = getTabHost();  // The activity TabHost     TabHost.TabSpec spec;  // Resusable TabSpec for each tab     Intent intent;  // Reusable Intent for each tab  try{    // Create an Intent to launch an Activity for the tab (to be reused)     intent = new Intent().setClass(this, ArtistsActivity.class);      // Initialize a TabSpec for each tab and add it to the TabHost     spec = tabHost.newTabSpec("artists").setIndicator("Artists",                       res.getDrawable(R.drawable.ic_tab_artists))                   .setContent(intent);     tabHost.addTab(spec);      // Do the same for the other tabs     intent = new Intent().setClass(this, AlbumsActivity.class);     spec = tabHost.newTabSpec("albums").setIndicator("Albums",                       res.getDrawable(R.drawable.ic_tab_artists1))                   .setContent(intent);     tabHost.addTab(spec);      intent = new Intent().setClass(this, SongsActivity.class);     spec = tabHost.newTabSpec("songs").setIndicator("Songs",                       res.getDrawable(R.drawable.ic_tab_artists2))                   .setContent(intent);     tabHost.addTab(spec);      tabHost.setCurrentTab(2);  }catch(Exception e){ e.printStackTrace(); } }}
?

热点排行