如何解决在Android Xamarin表单中调整标签栏图标的大小
大家好,我正在做一个xamarin项目,我正在向标签栏添加图标,但是图像看起来像这样。
我选择在IOS上使用它,但是Android给我带来了困难。我就像昨天一样了解到它不仅在制作自定义渲染器,而且还必须深入到layout文件夹并创建一个自定义axml文件。
无论如何,我在堆栈溢出时都遵循了这个非常有用的示例,我能够调整文本的大小,但是图像没有调整大小。本质上,我想使“选项卡”中的“文本”变小而“图标”变大。这是在IOS上完成的,但是就像我提到的那样,我在Android上苦苦挣扎。 以下是我到目前为止的内容。我认为我可能执行错了,因为其中提到的某些术语已被弃用,所以我不得不使用新方法来实现。
public class TabbedPageRendererAndriod : TabbedPageRenderer
{
public TabbedPageRendererAndriod(Context context) : base(context)
{
}
protected override void SetTabIconImageSource(TabLayout.Tab tab,Drawable icon)
{
base.SetTabIconImageSource(tab,icon);
tab.SetCustomView(Resource.Layout.CustomTab);
var imageView = tab.CustomView.FindViewById<ImageView>(Resource.Id.icon);
imageView.SetBackground(tab.Icon);
}
}
我的布局-> CustomTab.axml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitCenter"
android:id="@+id/icon"
android:layout_gravity="center_horizontal" />
</LinearLayout>
我现在了解该过程,但是不确定是否正确执行此操作。我还想指出,左边的图标是我要放大的图标。我还尝试添加较大的图像以查看是否需要,但是它们均默认为图像中显示的尺寸
解决方法
这可能会晚一点,但是我遇到了同样的问题。 我通过创建自定义渲染器解决了该问题:
[assembly: ExportRenderer(typeof(TabbedPage),typeof(CustomTabbedPageRenderer))]
namespace TabBarIconSize.Droid
{
class CustomTabbedPageRenderer : TabbedPageRenderer
{
public CustomTabbedPageRenderer(Context context)
: base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
{
base.OnElementChanged(e);
// Get TabbedPage's bottomNavigationView
var bottomNavigationView = (GetChildAt(0) as Android.Widget.RelativeLayout).GetChildAt(1) as BottomNavigationView;
// Set Icon size
bottomNavigationView.ItemIconSize = 50;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。