BloggerAds

2012年10月1日 星期一

Android - TabHost 分頁功能

 


請參考


http://jimmy319.blogspot.tw/2011/08/android-tab-view-content.html


但是裡面少說了如果要在分頁標題加上圖片該怎麼做


上面網址:(只有文字)setIndicator("文字");


解決方法:(文加圖)setIndicator("文字", getResources().getDrawable(R.drawable.details_icon));


tabHost.addTab(tabHost
.newTabSpec("tab_details")
.setIndicator(getString(R.string.tab_details), getResources().getDrawable(R.drawable.details_icon))
.setContent(R.id.tab_details)
);


But!!! 在4.0之後setIndicator(getString(R.string.tab_details), getResources().getDrawable(R.drawable.details_icon))


將沒用 如果你要讓文跟圖共存 必須要自製View layout 載入進去


參考: http://www.cnblogs.com/lovecode/articles/2652510.html