csharp Xamarin主题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Xamarin主题相关的知识,希望对你有一定的参考价值。

public enum ThemeType
{
	Dark,
	Light,
}
[XamlCompilation(XamlCompilationOptions.Compile)]
	public partial class LightTheme : ResourceDictionary
	{
		public LightTheme ()
		{
			InitializeComponent ();
		}
	}
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="TaxPon.View.Themes.LightTheme">
    <Color x:Key="BackgroundColor">#ecf0f1</Color>
    <Color x:Key="ForegroundColor">#33333c</Color>
    <Color x:Key="HeaderBackgroundColor">#2c3e50</Color>
    <Color x:Key="HeaderForegroundColor">#bdc3c7</Color>
    <Color x:Key="HeaderLogoColor">#1abc9c</Color>
    <Color x:Key="ListItemBackgroundColor">#bdc3c7</Color>
    <Color x:Key="ListItemTitleColor">#2980b9</Color>
</ResourceDictionary>

	
	[XamlCompilation(XamlCompilationOptions.Compile)]
	public partial class DarkTheme : ResourceDictionary
  {
		public DarkTheme ()
		{
			InitializeComponent ();
		}
	}
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="TaxPon.View.Themes.DarkTheme">
    <Color x:Key="BackgroundColor">Black</Color>
    <Color x:Key="ForegroundColor">#bdc3c7</Color>
    <Color x:Key="HeaderBackgroundColor">#20202a</Color>
    <Color x:Key="HeaderForegroundColor">#bdc3c7</Color>
    <Color x:Key="HeaderLogoColor">#1abc9c</Color>
    <Color x:Key="ListItemBackgroundColor">#1c1c1c</Color>
    <Color x:Key="ListItemTitleColor">#2980b9</Color>
</ResourceDictionary>

				/// <summary>
        /// テーマ変更
        /// </summary>
        /// <param name="theme">theme</param>
        /// <exception cref="NotImplementedException"></exception>
        public void ChangeTheme(ThemeType theme)
        {
            if (MainPage == null) return;

            MainPage.Parent = null;

            ResourceDictionary t = null;
            switch (theme)
            {
                case ThemeType.Dark:
                    t = new DarkTheme();
                    break;
                case ThemeType.Light:
                    t = new LightTheme();
                    break;
                default:
                    throw new NotImplementedException();
            }
            Application.Current.Resources.MergedDictionaries.Add(t);

            MainPage.Parent = this;
        }

以上是关于csharp Xamarin主题的主要内容,如果未能解决你的问题,请参考以下文章

csharp Xamarin RESX

csharp MyBindableCustomPicker / Xamarin.Forms

csharp Xamarin.Forms条目只有底部边框。

csharp Xamarin.Forms条目只有底部边框。

csharp Xamarin Android - Mostra tela em全屏

csharp Xamarin Android - Oculta o toolbar nativo