Android 控制項之TabHost Tab頁

2021-06-20 12:37:01 字數 1778 閱讀 8898

tabhost用來顯示tab頁,先看效果

一概述提供tab頁的視窗檢視容器,它有倆個children,一組是使用者可以選擇指定tab頁的標籤,另一組是framelayout用來顯示該tab頁的內容。個別元素通常控制使用這個容器物件,而不是設定在子元素本身的值。

二、重要方法

addtab(tabhost.tabspec tabspec):新增一項tab頁

getcurrenttab():返回當前tab頁.

gettabcontentview():返回包含內容的framelayout

newtabspec(string tag):返回乙個與之關聯的新的tabspec

三、例項

1.布局檔案,需要使用framelayout

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

"android:layout_width="match_parent"

android:layout_height="match_parent">

android:background="@drawable/b"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:text="頁1"/>

android:background="@drawable/c"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:text="頁2"/>

android:background="@drawable/d"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:text="頁3"/>

2.繼承tabactivity

public class tabhostdemo extends tabactivity

3.獲取次此abhost

tabhost tabhost = gettabhost();

4.設定布局

layoutinflater.from(this).inflate(r.layout.tabhostpage, tabhost.gettabcontentview(), true);

5.新增tab頁

tabhost.addtab(tabhost.newtabspec("tab1")

.setindicator("tab1")

.setcontent(r.id.view1));

tabhost.addtab(tabhost.newtabspec("tab3")

.setindicator("tab2")

.setcontent(r.id.view2));

tabhost.addtab(tabhost.newtabspec("tab3")

.setindicator("tab3")

.setcontent(r.id.view3));

**

Android之控制項

1.textview文字框的使用 新建乙個專案 model 選中到android 找到你新建的專案 res 移動到layout上新建乙個.xml檔案 片段內容如下 android layout width wrap content android layout height wrap content...

控制項縮小android控制項之WebView

工作之餘抽點時間出來寫寫博文,希望對新接觸的朋友有幫助。今天在這裡和大家一起學習一下控制項縮小 發現這個控制項挺好用,能自已控制進度條,而且這個控制項的功能非常壯大,後續再另說 先上個簡單的 每日一道理 青春是用意志的血滴和拼搏的汗水釀成的瓊漿 歷久彌香 青春是用不凋的希望和不滅的嚮往編織的彩虹 絢...

Android控制項之GridView

package com.example.gridviewtest import android.os.bundle import android.view.view import android.widget.adapterview import android.widget.adapterview...