Xamarin.ios 自定义选项卡页面颜色模式-Xamarin.Forms
有没有方法可以自定义Xamarin.ios 自定义选项卡页面颜色模式-Xamarin.Forms,xamarin.ios,xamarin,xamarin.android,xamarin.forms,tabbedpage,Xamarin.ios,Xamarin,Xamarin.android,Xamarin.forms,Tabbedpage,有没有方法可以自定义Xamarin.Forms.TabbedPage对象上选项卡的颜色模式,使其不采用目标平台的默认外观 我想更改字体颜色、背景和当前选定的选项卡颜色 Xamarin.Forms中没有内置方式,但在特定于平台的项目中,这非常容易做到。e、 g.通过在iOS上使用UIAppearance,我建议使用自定义渲染器 以下是iOS的一个示例: [assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer))
Xamarin.Forms.TabbedPage
对象上选项卡的颜色模式,使其不采用目标平台的默认外观
我想更改字体颜色、背景和当前选定的选项卡颜色 Xamarin.Forms中没有内置方式,但在特定于平台的项目中,这非常容易做到。e、 g.通过在iOS上使用UIAppearance,我建议使用自定义渲染器 以下是iOS的一个示例:
[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabbedPageRenderer))]
namespace MyApp.iOS
{
public class TabbedPageRenderer : TabbedRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
TabBar.TintColor = UIColor.White;
TabBar.BarTintColor = UIColor.Black;
TabBar.BackgroundColor = UIColor.Gray;
}
}
}
在Xamarin.iOS项目中刚刚通过这个课程
对于Xamarin.Android,您还可以使用自定义渲染器来完成相同的任务。定制渲染器的Android实现看起来与iOS版本不同。派对迟到了
现在,您可以如下更改选项卡式页面背景颜色
BarBackgroundColor=颜色。黑色强>
下面的链接可能会帮助你更多
我可以通过以下操作在Android中实现这一点: 将当前.MainPage强制转换为选项卡页-这将允许您设置属性
((TabbedPage)Current.MainPage).BarBackgroundColor = Color.FromHex(settings.AppSecondaryColour);
您应该能够以相同的方式更改其他属性。我还没有在IOS中测试过它。在选项卡式页面中,为了更改xamarin表单中的标题颜色,而不是android native中的标题颜色 选项卡式页面代码:
class MainPage : TabbedPage
{
LoginManager app;
public MainPage(LoginManager ilm)
{
app = ilm;
Title = "Infrastructure";
Icon = "server.png";
this.BarTextColor = Color.White;
this.BarBackgroundColor = Color.Blue;
Children.Add(new AssetsView());
Children.Add(new ServiceView());
ToolbarItem tbi = new ToolbarItem() {
Text = "Logout",
Order = ToolbarItemOrder.Secondary,
Priority = 0,
};
AssetView代码:
public AssetView()
{
Title = "Assets";
this.BackgroundColor = Color.FromHex("D3D3D3");
list = new AssetsList();
searchbar = new SearchBar()
{
Placeholder = "Search",
TextColor = Color.Black,
BackgroundColor = Color.White,
CancelButtonColor = Color.Black,
PlaceholderColor = Color.Black
};
public class ServiceView : ContentPage
{
ServiceList list;
SearchBar searchbar;
public ServiceView()
{
Title = "Services";
this.BackgroundColor = Color.FromHex("D3D3D3");
list = new ServiceList();
searchbar = new SearchBar()
{
Placeholder = "Search",
TextColor = Color.Black,
BackgroundColor = Color.White,
CancelButtonColor = Color.Black,
PlaceholderColor = Color.Black
};
ServiceView代码:
public AssetView()
{
Title = "Assets";
this.BackgroundColor = Color.FromHex("D3D3D3");
list = new AssetsList();
searchbar = new SearchBar()
{
Placeholder = "Search",
TextColor = Color.Black,
BackgroundColor = Color.White,
CancelButtonColor = Color.Black,
PlaceholderColor = Color.Black
};
public class ServiceView : ContentPage
{
ServiceList list;
SearchBar searchbar;
public ServiceView()
{
Title = "Services";
this.BackgroundColor = Color.FromHex("D3D3D3");
list = new ServiceList();
searchbar = new SearchBar()
{
Placeholder = "Search",
TextColor = Color.Black,
BackgroundColor = Color.White,
CancelButtonColor = Color.Black,
PlaceholderColor = Color.Black
};
您可以这样做:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:views="clr-namespace:SilCoyLuhn.Views"
x:Class="SilCoyLuhn.Views.MainPage"
BarBackgroundColor="{StaticResource Primary}"
BarTextColor="{StaticResource LightTextColor}">
<TabbedPage.Resources>
<ResourceDictionary>
<Color x:Key="Primary">#9DD69F</Color>
<Color x:Key="Accent">#E1F4E0</Color>
<Color x:Key="LightTextColor">#999999</Color>
</ResourceDictionary>
</TabbedPage.Resources>
</TabbedPage>
#9DD69F
#E1F4E0
#999999
在
中,我将静态资源定义为BarBackgroundColor
和BarTextColor
如何为Android实现这一点?