close

Android開發app時,有很多資訊想呈現,通常會使用分頁功能,讓頁面看起來資訊不擠,但是又讓使用者好搜尋。除了常見的Fragment外,這邊要介紹的是使用 Tabhost,我使用的版本如下:

3.jpg

 

TabhostLayout一定要有 TabHost(id: tabhost)TabWidget(id: tabs)FrameLayout(id: tabcontent)三個元件與其對應的idid名字不可以改,layout中的xml如下所示:

 

之後來看一下MainActivity中如何去加入新的頁面與控制頁面切換: (記得是繼承TabActivity)

 

然後記得去新增A1A2Empty ActivityAndroid Studio 新增 Empty Activity的功能也會把相對應的layout xml檔產生,也會幫你在AndroidManifest裡面做關聯。

1.jpg

 

2.jpg

3.jpg

 

主程式結構:

4.jpg

 

執行得到的畫面如下:

5.jpg

如果要讓頁籤的呈現變成底部呈現,直接在xml中的:

<TabHost> 這個標籤裡面加上:

android:layout_alignParentBottom="true"

並且把 <TabWidget> 放到 <FrameLayout>下方即可

 

如果要修改頁籤的字體大小,可使用下段程式碼:

 

 

打完收工

Reference:

https://blog.csdn.net/yongh701/article/details/75339620

https://stackoverflow.com/questions/5788971/how-to-change-the-font-size-of-tabhost-in-android

 

 

 

arrow
arrow

    葛瑞斯肯 發表在 痞客邦 留言(0) 人氣()