- TabTest.java
- view plaincopy to clipboardprint?
- package org.hualang.tab;
- import android.app.Activity;
- import android.app.TabActivity;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.widget.TabHost;
- import android.widget.Toast;
- import android.widget.TabHost.OnTabChangeListener;
- public class TabTest extends TabActivity {
-
- TabHost tabhost;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super .onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- tabhost = getTabHost();
-
-
-
-
- tabhost.addTab(tabhost.newTabSpec( "tab1" )
- .setIndicator( "TAB 1" ,getResources().getDrawable(R.drawable.img1))
- .setContent(R.id.text1));
- tabhost.addTab(tabhost.newTabSpec( "tab2" )
- .setIndicator( "TAB 2" ,getResources().getDrawable(R.drawable.img2))
- .setContent(R.id.text2));
- tabhost.addTab(tabhost.newTabSpec( "tab3" )
- .setIndicator( "TAB 3" ,getResources().getDrawable(R.drawable.img3))
- .setContent(R.id.text3));
-
-
-
- tabhost.setBackgroundResource(R.drawable.bg0);
-
- tabhost.setCurrentTab( 0 );
-
- tabhost.setOnTabChangedListener( new OnTabChangeListener()
- {
- public void onTabChanged(String tabId)
- {
- Toast toast=Toast.makeText(getApplicationContext(), "现在是" +tabId+ "标签" , Toast.LENGTH_SHORT);
- toast.show();
- }
- });
-
- }
- }
- xml version = "1.0" encoding = "utf-8" ?>
- < TabHost xmlns: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" >
- < TabWidget
- android:id = "@android:id/tabs"
- android:layout_width = "fill_parent"
- android:layout_height = "wrap_content" />
- < FrameLayout
- android:id = "@android:id/tabcontent"
- android:layout_width = "fill_parent"
- android:layout_height = "fill_parent" >
- < TextView
- android:id = "@+id/text1"
- android:layout_width = "fill_parent"
- android:layout_height = "fill_parent"
- android:text = "选项卡1" />
- < TextView
- android:id = "@+id/text2"
- android:layout_width = "fill_parent"
- android:layout_height = "fill_parent"
- android:text = "选项卡2" />
- < TextView
- android:id = "@+id/text3"
- android:layout_width = "fill_parent"
- android:layout_height = "fill_parent"
- android:text = "选项卡3" />
- FrameLayout >
- LinearLayout >
- TabHost >
阅读(1185) | 评论(0) | 转发(0) |