mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 01:48:25 +03:00
theme manager
This commit is contained in:
parent
fe52324eea
commit
3a90b3beb6
2 changed files with 27 additions and 16 deletions
|
@ -1,4 +1,5 @@
|
|||
using Bit.App.Pages;
|
||||
using Bit.App.Utilities;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Xamarin.Forms;
|
||||
|
@ -14,22 +15,7 @@ namespace Bit.App
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
// TODO: Load theme?
|
||||
if(false)
|
||||
{
|
||||
#pragma warning disable CS0162 // Unreachable code detected
|
||||
Resources.Add(
|
||||
#pragma warning restore CS0162 // Unreachable code detected
|
||||
StyleSheet.FromAssemblyResource(IntrospectionExtensions.GetTypeInfo(typeof(App)).Assembly,
|
||||
"Bit.App.Css.dark.css"));
|
||||
}
|
||||
Resources.Add(
|
||||
StyleSheet.FromAssemblyResource(IntrospectionExtensions.GetTypeInfo(typeof(App)).Assembly,
|
||||
"Bit.App.Css.styles.css"));
|
||||
Resources.Add(
|
||||
StyleSheet.FromAssemblyResource(IntrospectionExtensions.GetTypeInfo(typeof(App)).Assembly,
|
||||
$"Bit.App.Css.{Device.RuntimePlatform.ToLowerInvariant()}.css"));
|
||||
|
||||
ThemeManager.SetTheme("dark");
|
||||
MainPage = new TabsPage();
|
||||
}
|
||||
|
||||
|
|
25
src/App/Utilities/ThemeManager.cs
Normal file
25
src/App/Utilities/ThemeManager.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System.Reflection;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.StyleSheets;
|
||||
|
||||
namespace Bit.App.Utilities
|
||||
{
|
||||
public static class ThemeManager
|
||||
{
|
||||
public static void SetTheme(string name)
|
||||
{
|
||||
var themeFormat = "Bit.App.Css.{0}.css";
|
||||
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(App)).Assembly;
|
||||
// Other supported theme names can be added here.
|
||||
if(name == "dark")
|
||||
{
|
||||
Application.Current.Resources.Add(StyleSheet.FromAssemblyResource(assembly,
|
||||
string.Format(themeFormat, name)));
|
||||
}
|
||||
Application.Current.Resources.Add(StyleSheet.FromAssemblyResource(assembly,
|
||||
string.Format(themeFormat, Device.RuntimePlatform.ToLowerInvariant())));
|
||||
Application.Current.Resources.Add(StyleSheet.FromAssemblyResource(assembly,
|
||||
string.Format(themeFormat, "styles")));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue