国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 南宁市| 凤庆县| 湖州市| 西贡区| 望城县| 浦江县| 凉城县| 申扎县| 霍城县| 保康县| 白山市| 米易县| 南投市| 砀山县| 长垣县| 郧西县| 东阳市| 乡宁县| 顺昌县| 保亭| 望谟县| 德阳市| 太仆寺旗| 洱源县| 廉江市| 景谷| 磴口县| 利辛县| 类乌齐县| 尤溪县| 陆河县| 象州县| 师宗县| 晴隆县| 北流市| 栾城县| 牟定县| 庐江县| 山东省| 会同县| 博白县|