问题描述
Xamarin构成了Android我们如何更改选项卡式页面"图标大小的方式.我有正在使用AppCompact主题",我想在Tabbar.axaml中增加选项卡式页面"图标的大小
Xamarin forms Android how We change Tabbed Page Icon Size. I have Using AppCompact Themes and I want Increase Tabbed Page icon size in Tabbar.axaml
推荐答案
您可以在本地平台上创建自定义"渲染器并更改图标的大小.实际上,您可以覆盖整个选项卡的布局.
You can create a Custom renderer and change the size of icon in the native platform. Actually you can override the whole tab's layout.
例如,在PCL中首先创建一个从TabbedPage
继承的类:
For example, in PCL first create a class inherit from TabbedPage
:
public class MyTabbedPage : TabbedPage
{
}
然后在Android项目中创建其渲染器,例如:
Then create its renderer in Android project for example like this:
[assembly: ExportRenderer(typeof(MyTabbedPage), typeof(MyTabbedPageRenderer))]
namespace YourNameSpace.Droid
{
public class MyTabbedPageRenderer : TabbedPageRenderer
{
protected override void SetTabIcon(TabLayout.Tab tab, FileImageSource icon)
{
base.SetTabIcon(tab, icon);
tab.SetCustomView(Resource.Layout.mytablayout);
var imageview = tab.CustomView.FindViewById<ImageView>(Resource.Id.icon);
imageview.SetBackgroundDrawable(tab.Icon);
}
}
}
我创建的布局是这样的:
The layout I created is like this:
<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="50dp"
android:layout_height="50dp"
android:scaleType="fitCenter"
android:id="@+id/icon"
android:layout_gravity="center_horizontal" />
</LinearLayout>
如您所见,我直接在axml文件中设置大小.
As you can see, I set the size directly in the axml file.
当您要使用此自定义TabbedPage
时,可以例如这样的代码:
When you want to use this custom TabbedPage
, you can for example code like this:
<local:MyTabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TabbedPageForms"
x:Class="TabbedPageForms.MainPage">
<local:TodayPage Title="Today" Icon="hamburger.jpg" />
<local:SchedulePage Title="Schedule" Icon="hamburger.jpg" />
</local:MyTabbedPage>
后面的代码:
public partial class MainPage : MyTabbedPage
{
public MainPage()
{
InitializeComponent();
}
}
这篇关于Xamarin构成Android我们如何更改选项卡式页面图标大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!