如何在TabbedPage上进行设置

时间:2017-06-13 15:28:47

标签: xamarin.forms

Xamarin表格新手。

我有以下标签页。我想做以下事情:

1)标签的背景颜色为白色或一个有颜色,一个是白色。

2)更改Tab的下划线颜色。

3)我可以拥有多少个标签?

4)文本的字体大小。

5)由于每个Tab都有一个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 个答案:

答案 0 :(得分:0)

设置标签样式

需要在特定于平台的项目中处理选项卡背景颜色,文本大小和突出显示的样式。因此,对于Android,可以通过使用自定义主题覆盖基本样式来实现,您可以在参考资料&gt;中修改它们。值&gt; 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

标签计数

来自文档

  

如果该集合太大而无法放在一个屏幕上,则用户可以滚动屏幕顶部的标签集合。

实际上,标签的数量仅限于从用户体验的角度来看是有意义的。我个人认为不要超过6个,但是你的用例可以证明更多。