自訂豎型TabWidget

來源:互聯網
上載者:User
這個方法叫做“以假亂真法”先:
中心思想:把內建的TabWidget隱藏,自己建立一個左側的豎型tab欄,添加tab監聽,以此實現豎型tabwidget 第一步,建立menu.xml布局檔案<TabHost android:id= "@android:id/tabhost">     <TabWidget android:id= "@android:id/tabs" android:visibility= "gone"     <LinearLayout ></LinearLayout>     <FrameLayout android:id= "@android:id/tabcontent"/></TabHost>從id的取名就可以大致看出TabHost、TabWidget、FrameLayout各自的作用TabWidget--用來定義選項卡,此法裡面一定要有這句話android:visibility= "gone"FrameLayout--用來顯示選項卡對應的內容,通常是一些Activity中間的<LinearLayout>節點就有意思了,這個是“以假亂真”的關鍵。左側豎型tab就是在這個裡面定義的 第二步,建立每個Activity的xml檔案這裡所說的Activity就是要包含進右側frameLayout中的Activity 第三步,代碼實現tabWidget初始化// 得到TabHost對象            tabHost=
getTabHost();           Intent intent1 = newIntent( this,
MenuSetActivity. class);           // 第一個參數是用來指定標籤的;           // 第二個參數是顯示到頁面上的tag,在這裡不會顯示到頁面,因為設定visibility
gone;           // 第三個參數是選項卡內容     spec1= tabHost.newTabSpec( SETTAG).setIndicator( SETTAG).setContent(intent1);            tabHost.addTab(spec1); 第四步,添加監聽@Override      public voidonClick(View
v) {            intcheckedId
= v.getId();            if(currentId==
checkedId){                //當點擊的tab與當前tab一致時,返回                 return;           }            switch(checkedId)
{            caseR.id. systemset_set_text:                 setCurrentTabByTag( SETTAG);                 break;         }setCurrentTabByTag就是根據當前的tag去尋找相應的tab


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.