2012-11-21 53 views

回答

1

當我們添加分頁,我們TabHost,我們使用TabHost.newTabSpec( )創建一個TabSpec對象。使用默認選項卡外觀,我們將在TabSpec上調用setIndicator(String,Drawable)(傳遞要在選項卡上顯示的文本和圖像),然後在TabSpec上調用setContent(intent),傳遞一個Activity的意圖,我們希望被用作該標籤的內容。但是,在這種情況下,我們希望爲選項卡使用自定義佈局,並且我們只想將tab_activity_layout.xml中定義的視圖用於內容,而不是個別的活動。

對於自定義選項卡,首先,我們必須將選項卡的自定義佈局定義爲佈局資源文件。然後,我們將使用該佈局以編程方式膨脹View對象,設置我們想要的任何屬性,並將其傳遞到TabSpec.setIndicator(View)。這是一個很簡單的例子佈局,一些代碼使用它:請檢查鏈接

Custom View for Tab

0

如果使用代碼yourEditText.setTextSize(16); 或者如果您使用的.xml android:textSize="16sp"

0

你只可以使你的自定義選項卡按鈕,這是非常容易和簡單:

爲該選項卡創建一個像xml佈局一樣的常規選項。例如:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:id="@+id/rlayout" 
    android:gravity="center_vertical|center_horizontal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <ImageView 
     android:id="@+id/icon4" 
     android:src="@drawable/somedrawable" 
     android:layout_height="42dp" 
     android:layout_width="42dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="News" 
     android:textSize="12dp" 
     android:textStyle="bold" 
     android:textColor="#FFFFFF" 
     android:paddingBottom="1dp" 
     android:layout_below ="@+id/icon4"/> 

</LinearLayout> 
在標籤活動類

然後infalte這樣的佈局,像這樣:

LayoutInflater inflater0 = LayoutInflater.from(this); 
View view0 = inflater0.inflate(R.layout.tabbuttonlayout, null); 

後來才用它通常在標籤主持人:

th = getTabHost(); 
th.addTab(th.newTabSpec("tag0").setIndicator(view0).setContent(intent0)); 

我希望這有助於更好地定製您的選項卡。

+1

其真正的工作....感謝很多......並感謝上帝解決我的問題..... – jhon

相關問題