TabHost的使用方法

2021-08-30 20:39:35 字數 1146 閱讀 7810

tabhost的使用方法

方法一:

繼承tabactivity

獲取系統提供的tabhost

用layoutinflater為其設定content

新增tab選項

具體**如下:

tabhost th = this.gettabhost();

layoutinflater li = this.getlayoutinflater();

li.inflate(r.layout.layout1,th.gettabcontentview());

li.inflate(r.layout.layout2,th.gettabcontentview()); th.addtab(th.newtabspec("tab1").setindicator("first").setcontent(r.id.layout1)); th.addtab(th.newtabspec("tab2").setindicator("second").setcontent(r.id.layout2));

方法二:

繼承activity

用xml語言為其進行設定

獲取tabhost的方法為findviewbyid

後面需跟一句setup();

具體**如下:

setcontentview(r.layout.main);

tabhost th = (tabhost)findviewbyid(r.id.main);

th.setup();

layoutinflater li = this.getlayoutinflater();

li.inflate(r.layout.layout1, th.gettabcontentview());

li.inflate(r.layout.layout2, th.gettabcontentview()); th.addtab(th.newtabspec("tab1").setindicator("first").setcontent(r.id.layout1)); th.addtab(th.newtabspec("tab2").setindicator("second").setcontent(r.id.layout2));

xml檔案具體如下:

<?xml version="1.0" encoding="utf-8"?>

TabHost的使用方法

第一步 建立main.xml檔案 android id android id tabhost android layout width fill parent android layout height fill parent 第二步驟 編輯mainactivity package cn.hjw.t...

TabHost的使用方法

tabhost 是整個tab 的容器,包括兩部分,tabwidget 和framelayout tabwidget 就是每個 tab的標籤,framelayout 則是tab 內容。tabhost有兩種實現方式 一 繼承tabactivity 二 單純繼承activity,在 中新增 第一種 1 如...

TabHost簡單使用示例

在android的開發中,經常需要實現頁面tab的功能,比較簡答的一種方式就是使用tabhost實現。顧名思義,tabhost即是包含若干個tab的乙個tab容器。那麼,當我們要使用tabhost實現乙個介面功能的時候,我們是如何開始的呢?布局檔案的填寫較為簡單,如下 使用中,需要注意的點是 tab...