3 using Tizen.NUI.Components;
4 using Tizen.NUI.BaseComponents;
5 using Tizen.Applications.ThemeManager;
7 namespace Tizen.NUI.Samples
9 public class ThemeChangeSample : IExample
11 private ThemeLoader themeLoader;
13 public void Activate()
15 themeLoader = new ThemeLoader();
17 var mainPage = new ContentPage()
19 ThemeChangeSensitive = true,
22 AutoNavigationContent = false,
23 Title = "NUI theme sample",
24 //Actions = new View[] { closeButton },
26 Content = new ScrollableBase()
28 Layout = new LinearLayout()
30 LinearOrientation = LinearLayout.Orientation.Vertical,
31 CellPadding = new Size2D(20, 20)
33 WidthResizePolicy = ResizePolicyType.FillToParent,
34 HeightResizePolicy = ResizePolicyType.FillToParent,
35 Padding = new Extents(30, 30, 20, 20)
39 string[] ids = (string[])themeLoader.QueryIds();
40 if (ids != null && ids.Contains("org.tizen.default-dark-theme") || ids.Contains("org.tizen.default-light-theme"))
42 var title = $"Current theme: {(themeLoader.CurrentTheme.Id == "org.tizen.default-dark-theme" ? "Dark" : "Light")}";
44 mainPage.Content.Add(CreateClickableItem("Theme change", title, delegate (View view)
46 TextLabel text = view.Children[1] as TextLabel;
48 if (themeLoader.CurrentTheme.Id == "org.tizen.default-dark-theme")
50 var theme = themeLoader.LoadTheme("org.tizen.default-light-theme");
51 Tizen.Log.Info("test", $"Id: {theme.Id}, Version: {theme.Version}");
52 themeLoader.CurrentTheme = theme;
53 text.Text = "Current theme: Light";
57 var theme = themeLoader.LoadTheme("org.tizen.default-dark-theme");
58 Tizen.Log.Info("test", $"Id: {theme.Id}, Version: {theme.Version}");
59 themeLoader.CurrentTheme = theme;
60 text.Text = "Current theme: Dark";
64 mainPage.Content.Add(CreateItem("Switch", CreateSwitchExample()));
68 mainPage.AppBar.Title = "No proper theme is found!";
71 NUIApplication.GetDefaultWindow().GetDefaultNavigator().Push(mainPage);
74 public void Deactivate()
76 NUIApplication.GetDefaultWindow().GetDefaultNavigator().Pop();
78 themeLoader.Dispose();
82 private View CreateItem(string title, View content)
86 WidthResizePolicy = ResizePolicyType.FillToParent,
87 HeightResizePolicy = ResizePolicyType.FitToChildren,
88 Layout = new LinearLayout()
90 LinearOrientation = LinearLayout.Orientation.Vertical,
92 BackgroundColor = new Color("#88888860"),
96 item.Add(new TextLabel()
100 Padding = new Extents(0, 0, 0, 20)
106 private View CreateClickableItem(string title, string subtitle, Action<View> clicked)
108 var item = new View()
110 WidthResizePolicy = ResizePolicyType.FillToParent,
111 HeightResizePolicy = ResizePolicyType.FitToChildren,
112 Layout = new LinearLayout()
114 LinearOrientation = LinearLayout.Orientation.Vertical,
116 BackgroundColor = new Color("#88888860"),
117 CornerRadius = 16.0f,
119 LeaveRequired = true,
121 item.TouchEvent += (s, e) => {
122 var state = e.Touch.GetState(0);
123 if (state == PointStateType.Down)
125 ((View)s).BackgroundColor = new Color("#888888BB");
127 else if (state == PointStateType.Up)
129 ((View)s).BackgroundColor = new Color("#88888860");
130 clicked?.Invoke(item);
132 else if (state == PointStateType.Leave || state == PointStateType.Interrupted)
134 ((View)s).BackgroundColor = new Color("#88888860");
138 item.Add(new TextLabel()
142 Padding = new Extents(0, 0, 0, 20)
144 item.Add(new TextLabel()
148 VerticalAlignment = VerticalAlignment.Center,
153 private View CreateSwitchExample()
155 var view = new View()
157 WidthResizePolicy = ResizePolicyType.FillToParent,
158 HeightResizePolicy = ResizePolicyType.FitToChildren,
160 var textLabel = new TextLabel()
162 Text = "Auto update : on",
163 TextColor = Color.Red,
167 var switchButton = new Switch()
169 ParentOrigin = ParentOrigin.CenterRight,
170 PivotPoint = PivotPoint.CenterRight,
171 PositionUsesPivotPoint = true,
174 switchButton.SelectedChanged += (s, e) => {
175 textLabel.Text = $"Daily auto update : {(((Switch)s).IsSelected ? "on" : "off")}";
177 view.Add(switchButton);