国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

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

2020-04-11 12:00:05
字體:
供稿:網(wǎng)友

首先,定義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個      
                     my_tabhost.setCurrentTab(1);

    }

}

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 弥勒县| 丰原市| 丹寨县| 佳木斯市| 沅江市| 清丰县| 苏尼特右旗| 江山市| 禄丰县| 神农架林区| 那曲县| 南江县| 红桥区| 湖州市| 台安县| 醴陵市| 邵阳县| 中阳县| 托里县| 天峨县| 莱芜市| 淮南市| 油尖旺区| 弥渡县| 奇台县| 阳信县| 西乌| 泌阳县| 大方县| 沽源县| 临沭县| 北票市| 余干县| 绥德县| 潼关县| 沙洋县| 临海市| 昌图县| 天峨县| 富顺县| 麦盖提县|