2

我制作了一个自定义渲染器,用于在 Android 平台的选项卡中显示图像。现在我想知道如何删除显示选择了哪个选项卡的底线。另外,我在哪里可以获得有关创建自定义渲染器的信息?我在 youtube 上看过,但圆角的例子并没有显示太多......

namespace Plopsa.Android
{
public class CustomTabRenderer: TabbedRenderer 
{
    private Activity _activity;

    protected override void OnModelChanged(VisualElement oldModel, VisualElement newModel)
    {
        base.OnModelChanged(oldModel, newModel);

        _activity = this.Context as Activity;
    }

    // May put this code in a different method - was just for testing
    public override void OnWindowFocusChanged(bool hasWindowFocus)
    {   
        // Here the magic happens:  get your ActionBar and select the tab you want to add an image
        ActionBar actionBar = _activity.ActionBar;

        if (actionBar.TabCount > 0)
        {
            ActionBar.Tab tabOne = actionBar.GetTabAt(0);
            tabOne.SetIcon(Resource.Drawable.icon_tab1);

            ActionBar.Tab tabTwo = actionBar.GetTabAt(1);
            tabTwo.SetIcon (Resource.Drawable.icon_tab2);

            ActionBar.Tab tabThree = actionBar.GetTabAt(2);
            tabThree.SetIcon(Resource.Drawable.icon_tab3);

            ActionBar.Tab tabFour = actionBar.GetTabAt(3);
            tabFour.SetIcon(Resource.Drawable.icon_tab4);

        }
        base.OnWindowFocusChanged(hasWindowFocus);
    }
}
4

1 回答 1

0

您可以通过将 Tabbar.axml 类 'android:tabIndicatorColor' 设置为与 'android:background' 相同的值来实现所需的结果。

下面是显示所需结果的代码,其中带有与选项卡背景颜色匹配的选项卡指示器。这都包含在 Tabbar.axml 文件中。您可以在 MainActivitiy.cs 中注册选项卡。

标签栏.axml

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" app:tabTextAppearance="@style/MyCustomTabText" android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.Light" app:tabTextColor="@color/primaryOrange" app:tabIndicatorColor="?attr/colorPrimary" app:tabIndicatorHeight="0dp" app:tabSelectedTextColor="@color/primaryOrange" app:tabGravity="fill" app:tabMode="fixed" /> MainActivity.cs

 protected override void OnCreate(Bundle bundle)
        {

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.

            base.OnCreate(bundle);

            Xamarin.Forms.Forms.Init(this, bundle);

            LoadApplication(new App());

        }

示例结果

在此处输入图像描述

于 2017-01-10T13:34:42.880 回答