a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

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

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

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即是選項卡上面的標(biāo)簽,F(xiàn)rameLayout是選項卡的內(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)選中的選項卡為第2個      
                     my_tabhost.setCurrentTab(1);

    }

}

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 亚洲免费一区二区 | 中文字幕亚洲字幕一区二区 | 黄瓜av | 秋霞a级毛片在线看 | 欧美日韩在线一区 | 国产精品国产精品国产 | 日韩精品久久 | 欧美一级黄色片 | 国产成人精品一区一区一区 | 久久精品视频一区二区 | 欧美一区二区三区在线视频 | 日日夜夜精品免费视频 | 欧美一级免费 | 国产精品99久久免费观看 | 国产精品久久国产精麻豆99网站 | 国产乱人伦av在线a 久久精品视 | 精品国产一区二区三区av片 | 九一在线观看 | 欧美精品一区二区三区在线四季 | www.色综合| 欧美一级免费播放 | 91丝袜| 国产福利视频在线观看 | 欧美一级片 | 91免费在线播放 | 亚洲精品1 | 狠狠操夜夜操天天操 | 玖玖色资源 | 一区二区亚洲 | 99久久99久久免费精品蜜臀 | 国产四区| 97伦理电影院 | 中国国产一级毛片 | 亚洲久草| 亚洲精品一区二区三区蜜桃久 | 欧美精品在线一区二区三区 | 北条麻妃99精品青青久久 | 拍真实国产伦偷精品 | 色吧久久| 欧美日韩导航 | 午夜一级毛片 |