微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Xamarin android,如何使标签页图标更大

如何解决Xamarin android,如何使标签页图标更大

我正在使用 Xamarin.android。

建立一个标签页。并使用一个图标作为每个工作表的标题,如下所示。

但是图像比面积小得多。

有没有可能让它变大?

enter image description here

解决方法

建立一个标签页。并使用一个图标作为每个工作表的标题,如下所示。但图像比面积小得多。是否可以将其放大?

如果你想让TabbedPage图标变大,你必须自己制作一个自定义渲染器来实现。

首先,在 Android 平台中创建一个自定义渲染器 MyTabbedPageRenderer.cs

[assembly: ExportRenderer(typeof(TabbedPage),typeof(MyTabbedPageRenderer))]
namespace FormsSample.Droid
{
public class MyTabbedPageRenderer : TabbedPageRenderer
{
    public MyTabbedPageRenderer(Context context) : base(context)
    {

    }

    protected override void SetTabIcon(TabLayout.Tab tab,FileImageSource icon)
    {
        base.SetTabIcon(tab,icon);
        tab.SetCustomView(Resource.Layout.Custom_tab_layou);

        var imageview = tab.CustomView.FindViewById<ImageView>(Resource.Id.icon);

        var textview = tab.CustomView.FindViewById<TextView>(Resource.Id.tv);
        textview.Text = tab.Text;

        imageview.SetBackgroundDrawable(tab.Icon);

    }
}
}

然后为 TabbedPage 选项卡创建自定义选项卡,添加 ImageView 和 TevtView 以显示 TabbedPage 的图标和标题。您可以使 ImageView layout_height 更大以显示图标。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:orientation="vertical">
<ImageView
    android:id="@+id/icon"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_gravity="center_vertical"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="4dp"
    android:layout_marginBottom="4dp" />
<TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"       
    android:gravity="center"
    android:textSize="11dp"
    android:textColor="#00FF6F" />

这是截图:

enter image description here

标签页:

<TabbedPage
x:Class="FormsSample.tabbedpage.TabbedPage5"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<!--  Pages can be added as references or inline  -->
<ContentPage Title="Tab 1" IconImageSource="favorite.png" />
<ContentPage Title="Tab 2" IconImageSource="check.png" />
<ContentPage Title="Tab 3" IconImageSource="flag.png" />

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。