2017-06-13 78 views
1

的設置。如何在Xamarin表格中新增TabbedPage

我有以下選項卡式頁面。我想要做到以下幾點:

1)背景顏色的標籤是白色或一個顏色,一個白色。

2)改變Tab下劃線的顏色。

3)我可以有多少Tab?

4)Text的字體大小。 5)由於每個標籤都有一個contentPage,所以如何從外部引用contentPage,而不是在Tab中,因爲我的內容頁非常長且複雜。

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      BackgroundColor="White" 
      x:Class="MainPage2"> 

    <ContentPage Title ="Page1" Icon="itemIcon1" WidthRequest="200" BackgroundColor="White"> 

     <ContentPage.Content> 

      <StackLayout VerticalOptions="Center" HorizontalOptions="Center"> 


       <Label Text="T1"> 
       </Label> 

      </StackLayout> 

     </ContentPage.Content> 
    </ContentPage> 

    <ContentPage Title ="Page2" Icon="itemIcon2" WidthRequest="200" BackgroundColor="White"> 

     <ContentPage.Content> 

      <StackLayout VerticalOptions="Center" HorizontalOptions="Center"> 

       <Label Text="T2"> 
       </Label> 

      </StackLayout> 

     </ContentPage.Content> 
    </ContentPage> 



    <ContentPage Title ="Page3" Icon="itemIcon3" WidthRequest="200"> 

     <ContentPage.Content> 

      <StackLayout VerticalOptions="Center" HorizontalOptions="Center"> 

       <Label Text="T3"> 
       </Label> 
      </StackLayout> 

     </ContentPage.Content> 
    </ContentPage> 
</TabbedPage> 

感謝

+1

您在這裏擔心哪些平臺?看起來只是Android,但是你是否也需要在iOS上進行大量的定製?特別是「標籤的下劃線」 – SuavePirate

回答

0

樣式化標籤

的樣式選項卡的背景顏色,文字大小,並重點將需要在你的平臺特定的項目進行處理。因此,針對Android這可以通過使用自定義主題,你可以在資源修改>重寫基款式達到的值>styles.xml

<?xml version="1.0" encoding="UTF-8"?> 
<resources> 
    <color name="CustomHighlight">@android:color/transparent</color> 

    <style name="MyTheme" parent="MyTheme.Base"> 
    </style> 

    <!-- Base theme applied no matter what API --> 
    <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <item name="android:tabWidgetStyle">@android:style/Widget.TabWidget</item> 
     ... 
     <!-- The rest of your styles would go here --> 
     ... 
    </style> 
    <style name="Widget.TabWidget"> 
     <item name="android:textAppearance">@style/TextAppearance.Widget.TabWidget</item> 
     <item name="android:ellipsize">marquee</item> 
     <item name="android:singleLine">true</item> 
    </style> 


    <style name="TextAppearance.Widget.TabWidget"> 
     <item name="android:textSize">14sp</item> 
     <item name="android:textStyle">normal</item> 
     <item name="android:textColor">@android:color/tab_indicator_text</item> 
    </style> 
</resources> 

(塗抹適量來自這個問題借來的:Android - How to Change Color of Selected Tab

您在直插式的背景顏色應該在你的.xaml標記足夠了:

<ContentPage Title ="Page2" Icon="itemIcon2" WidthRequest="200" BackgroundColor="White"> 

對於iOS,改變高亮顏色是相當微不足道。在您的AppDelegate.cs

public override bool FinishedLaunching(UIApplication app, NSDictionary options) 
{ 
    UITabBar.Appearance.TintColor = UIColor.Red; 

    global::Xamarin.Forms.Forms.Init(); 

    ... 

,事情就從那裏毛茸茸的,所以我將把你的開發者文檔,其中有用於創建自定義呈現一個偉大的演練:Customize Tab Bar on iOS

選項卡數

來自文檔

用戶可以滾動acr選項卡的集合如果該集合太大而不適合在一個屏幕上,則oss在屏幕的頂部。

真的,標籤的數量僅限於從用戶體驗的角度來看有意義。我個人儘量不要超過6個,但是你的用例可能需要更多。

相關問題