欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android TabHost(選項(xiàng)卡)的使用方法

 更新時(shí)間:2013年11月19日 11:18:36   作者:  
Android中的選項(xiàng)卡是用TabHost實(shí)現(xiàn)的,下面我們用一個(gè)例子說明他的使用方法

首先,定義TabHost的布局文件:

復(fù)制代碼 代碼如下:

<?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">

        <TabWidget android:id="@android:id/tabs"
            android:layout_alignParentBottom="true"
            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" />

    </LinearLayout>

</TabHost>

其中,TabWidget即是選項(xiàng)卡上面的標(biāo)簽,F(xiàn)rameLayout是選項(xiàng)卡的內(nèi)容。
在Java類文件中定義如下:

復(fù)制代碼 代碼如下:

public class MainActivity extends TabActivity {

    private TabHost my_tabhost; 
    private TabWidget my_tabwidget;
    private int i,k;
    private TextView tv;

    private String[] tabMenu = { "系統(tǒng)", "硬件", "操作"};
    private Intent intent0, intent1, intent2;
    private Intent[] intents = { intent0, intent1, intent2};
    private TabHost.TabSpec tabSpec0, tabSpec1, tabSpec2, tabSpec3;
    private TabHost.TabSpec[] tabSpecs = { tabSpec0, tabSpec1, tabSpec2, tabSpec3};

    public static Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                // 不要窗體標(biāo)題
               requestWindowFeature(Window.FEATURE_NO_TITLE);
               setContentView(R.layout.activity_main);
        setContentView(R.layout.activity_main);

        my_tabhost = getTabHost();

        intent0 = new Intent(this, system.class);
        intent1 = new Intent(this, hardware.class);
        intent2 = new Intent(this, operation.class);

        tabSpec0 = my_tabhost.newTabSpec("system").setIndicator(tabMenu[0],null).
                setContent(intent0);
        tabSpec1 = my_tabhost.newTabSpec("hardware").setIndicator(tabMenu[1],null).
                setContent(intent1);
        tabSpec2 = my_tabhost.newTabSpec("operation").setIndicator(tabMenu[2],null).
                setContent(intent2);

        my_tabhost.addTab(tabSpec1);
        my_tabhost.addTab(tabSpec0);
        my_tabhost.addTab(tabSpec2);
<br>                 // 設(shè)置默認(rèn)選中的選項(xiàng)卡為第2個(gè)      
                     my_tabhost.setCurrentTab(1);

    }

}

每一個(gè)選項(xiàng)卡對(duì)應(yīng)一個(gè)Intent,每一個(gè)Intent又對(duì)應(yīng)一個(gè)類,選中這個(gè)選項(xiàng)卡時(shí),就顯示對(duì)應(yīng)的類。
運(yùn)行結(jié)果如下:

相關(guān)文章

最新評(píng)論