首页 > 解决方案 > 如何制作自定义标签页?(底部圆角框)

问题描述

如何制作自定义标签页?对不起一个愚蠢的问题,但请帮忙。也许现在有人如何制作这样的自定义标签页我不知道如何在底部制作这个圆形框架来自定义标签页

在此处输入图像描述

标签: c#xamlxamarinxamarin.formscustomization

解决方案


安卓:

shape_indicator_radius.xml在drawable文件夹中添加:

<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"  >
  <corners android:bottomRightRadius="50dp" android:bottomLeftRadius="50dp"/>
  <solid
       android:color="@android:color/black"/>
</shape>

在 Tabbar.xml 中设置背景:

<?xml version="1.0" encoding="utf-8"?>
 <android.support.design.widget.TabLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" 
android:background="@drawable/shape_indicator_radius">

</android.support.design.widget.TabLayout>

在 MainActivity 中,设置TabLayoutResourceOnCreate 方法。

 TabLayoutResource = Resource.Layout.Tabbar;

IOS:

您可以使用自定义渲染器来做到这一点。

[assembly:ExportRenderer(typeof(TabbedPage),typeof(MyCustomRenderer))]
namespace App4.iOS
{
    class MyCustomRenderer: TabbedRenderer
    {
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            this.TabBar.Layer.MasksToBounds = true;
            this.TabBar.Translucent = true;
            
            this.TabBar.BarStyle = UIBarStyle.Black;
            this.TabBar.Layer.CornerRadius = 50;
            this.TabBar.Layer.MaskedCorners = 
            CoreAnimation.CACornerMask.MaxXMinYCorner | 
            CoreAnimation.CACornerMask.MinXMinYCorner;
        }
    }
   
}

推荐阅读