1 using System.Collections.Generic;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
5 namespace Tizen.NUI.Samples
7 public class ButtonSample : IExample
16 Button iconTextButton;
18 Button utilityBasicButton;
19 Button utilityServiceButton;
20 Button utilityToggleButton;
21 Button utilityOvalButton;
23 Button familyBasicButton;
24 Button familyServiceButton;
25 Button familyToggleButton;
26 Button familyOvalButton;
28 public void Activate()
30 Window window = NUIApplication.GetDefaultWindow();
33 Size = new Size(1920, 1080),
34 BackgroundColor = new Color(0.7f, 0.9f, 0.8f, 1.0f),
35 Layout = new LinearLayout()
37 LinearAlignment = LinearLayout.Alignment.Center,
38 LinearOrientation = LinearLayout.Orientation.Horizontal,
39 CellPadding = new Size(50, 50),
43 window.KeyEvent += Window_KeyEvent;
47 Size = new Size(300, 900),
48 Layout = new LinearLayout()
50 LinearAlignment = LinearLayout.Alignment.Top,
51 LinearOrientation = LinearLayout.Orientation.Vertical,
52 CellPadding = new Size(50, 50),
58 Size = new Size(300, 900),
59 Layout = new LinearLayout()
61 LinearAlignment = LinearLayout.Alignment.Top,
62 LinearOrientation = LinearLayout.Orientation.Vertical,
63 CellPadding = new Size(50, 50),
67 // Only show a text button.
68 textButton = new Button();
69 textButton.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
70 textButton.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
71 textButton.Size = new Size(300, 80);
72 textButton.TextLabel.Text = "Button";
73 parent1.Add(textButton);
75 //Only show an icon button.
76 iconButton = new Button();
78 iconButton.Name = "IconButton";
79 iconButton.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
80 iconButton.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
81 iconButton.Size = new Size(80, 80);
82 iconButton.Icon.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_radiobutton/c_radiobutton_white_check.png";
83 parent2.Add(iconButton);
84 iconButton.ClickEvent += (ojb, e) => {
85 var btn = iconButton.Icon.GetParent() as Button;
86 string name = btn.Name;
91 Size = new Size(600, 400),
92 Layout = new LinearLayout()
94 LinearAlignment = LinearLayout.Alignment.Top,
95 LinearOrientation = LinearLayout.Orientation.Vertical,
96 CellPadding = new Size(50, 50),
100 //Show a button with icon and text.
101 iconTextButton = new Button();
102 iconTextButton.Text = "IconTextButton";
103 iconTextButton.BackgroundImage = CommonResource.GetTVResourcePath() + "component/c_buttonbasic/c_basic_button_white_bg_normal_9patch.png";
104 iconTextButton.BackgroundImageBorder = new Rectangle(4, 4, 5, 5);
105 iconTextButton.IconRelativeOrientation = Button.IconOrientation.Left;
106 iconTextButton.Icon.ResourceUrl = CommonResource.GetTVResourcePath() + "component/c_radiobutton/c_radiobutton_white_check.png";
107 iconTextButton.IconPadding = new Extents(20, 20, 20, 20);
108 iconTextButton.TextPadding = new Extents(20, 50, 20, 20);
109 iconTextButton.Size = new Size(500, 300);
110 parent3.Add(iconTextButton);
112 ///////////////////////////////////////////////Create by Property//////////////////////////////////////////////////////////
113 //Create utility basic style of button.
114 var utilityBasicButtonStyle = new ButtonStyle()
116 Overlay = new ImageViewStyle()
118 ResourceUrl = new Selector<string>
120 Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
123 Border = new Rectangle(5, 5, 5, 5)
125 Text = new TextLabelStyle()
127 TextColor = new Selector<Color>
129 Normal = new Color(0, 0, 0, 1),
130 Pressed = new Color(0, 0, 0, 0.7f),
131 Selected = new Color(0.058f, 0.631f, 0.92f, 1),
132 Disabled = new Color(0, 0, 0, 0.4f)
134 Text = "UtilityBasicButton",
137 BackgroundImage = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png",
138 BackgroundImageBorder = new Rectangle(5, 5, 5, 5),
140 utilityBasicButton = new Button();
141 utilityBasicButton.ApplyStyle(utilityBasicButtonStyle);
142 utilityBasicButton.IsSelectable = true;
143 utilityBasicButton.ImageShadow = new ImageShadow
145 Url = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png",
146 Border = new Rectangle(5, 5, 5, 5)
148 utilityBasicButton.Size = new Size(300, 80);
149 utilityBasicButton.IsEnabled = false;
150 parent1.Add(utilityBasicButton);
152 //Create utility service style of button.
153 var utilityServiceButtonStyle = new ButtonStyle()
155 Overlay = new ImageViewStyle()
157 ResourceUrl = new Selector<string>
159 Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
162 Border = new Rectangle(5, 5, 5, 5)
164 Text = new TextLabelStyle()
166 TextColor = new Selector<Color>
168 Normal = new Color(1, 1, 1, 1),
169 Pressed = new Color(1, 1, 1, 0.7f),
170 Disabled = new Color(1, 1, 1, 0.4f)
172 Text = "ServiceBasicButton",
175 BackgroundImage = CommonResource.GetFHResourcePath() + "3. Button/rectangle_point_btn_normal.png",
176 BackgroundImageBorder = new Rectangle(5, 5, 5, 5)
178 utilityServiceButton = new Button();
179 utilityServiceButton.ApplyStyle(utilityServiceButtonStyle);
180 utilityServiceButton.ImageShadow = new ImageShadow
182 Url = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png",
183 Border = new Rectangle(5, 5, 5, 5)
186 utilityServiceButton.Size = new Size(300, 80);
187 parent1.Add(utilityServiceButton);
189 //Create utility toggle style of button.
190 var utilityToggleButtonStyle = new ButtonStyle()
192 BackgroundImage = new Selector<string>
194 Normal = CommonResource.GetFHResourcePath() + "3. Button/rectangle_toggle_btn_normal.png",
195 Selected = CommonResource.GetFHResourcePath() + "3. Button/rectangle_point_btn_normal.png",
197 Overlay = new ImageViewStyle()
199 ResourceUrl = new Selector<string>
201 Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png",
205 Text = new TextLabelStyle()
207 TextColor = new Selector<Color>
209 Normal = new Color(0.058f, 0.631f, 0.92f, 1),
210 Selected = new Color(1, 1, 1, 1),
212 Text = new Selector<string>
214 Normal = "Toggle Off",
215 Selected = "Toggle On"
219 BackgroundColor = new Selector<Color>()
221 utilityToggleButton = new Button();
222 utilityToggleButton.ApplyStyle(utilityToggleButtonStyle);
223 utilityToggleButton.IsSelectable = true;
224 utilityToggleButton.BackgroundImageBorder = new Rectangle(5, 5, 5, 5);
225 utilityToggleButton.ImageShadow = new ImageShadow
227 Url = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png",
228 Border = new Rectangle(5, 5, 5, 5)
230 utilityToggleButton.OverlayImage.Border = new Rectangle(5, 5, 5, 5);
232 utilityToggleButton.Size = new Size(300, 80);
233 parent1.Add(utilityToggleButton);
235 //Create utility oval style of button.
236 var utilityOvalButtonStyle = new ButtonStyle()
238 BackgroundImage = new Selector<string>
240 Normal = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_normal.png",
241 Selected = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_select.png",
243 Overlay = new ImageViewStyle()
245 ResourceUrl = new Selector<string>
247 Pressed = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_press_overlay.png",
251 Text = new TextLabelStyle()
255 BackgroundColor = new Selector<Color>(),
257 utilityOvalButton = new Button();
258 utilityOvalButton.ApplyStyle(utilityOvalButtonStyle);
259 utilityOvalButton.IsSelectable = true;
260 utilityOvalButton.BackgroundImageBorder = new Rectangle(5, 5, 5, 5);
261 utilityOvalButton.ImageShadow = new ImageShadow
263 Url = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_shadow.png",
264 Border = new Rectangle(5, 5, 5, 5)
266 utilityOvalButton.OverlayImage.Border = new Rectangle(5, 5, 5, 5);
268 utilityOvalButton.Size = new Size(104, 104);
269 utilityOvalButton.TextLabel.PointSize = 20;
270 parent1.Add(utilityOvalButton);
272 ///////////////////////////////////////////////Create by Attributes//////////////////////////////////////////////////////////
273 //Create family basic style of Button.
274 ButtonStyle familyBasicButtonStyle = new ButtonStyle
277 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_normal.png" },
278 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
279 ImageShadow = new ImageShadow
281 Url = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png",
282 Border = new Rectangle(5, 5, 5, 5)
285 Overlay = new ImageViewStyle
287 ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
288 Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
291 Text = new TextLabelStyle
293 PointSize = new Selector<float?> { All = 20 },
294 HorizontalAlignment = HorizontalAlignment.Center,
295 VerticalAlignment = VerticalAlignment.Center,
296 WidthResizePolicy = ResizePolicyType.FillToParent,
297 HeightResizePolicy = ResizePolicyType.FillToParent,
299 TextColor = new Selector<Color>
301 Normal = new Color(0, 0, 0, 1),
302 Pressed = new Color(0, 0, 0, 0.7f),
303 Selected = new Color(0.141f, 0.769f, 0.278f, 1),
304 Disabled = new Color(0, 0, 0, 0.4f),
306 Text = "FamilyBasicButton",
309 familyBasicButton = new Button(familyBasicButtonStyle);
310 familyBasicButton.Size = new Size(300, 80);
311 parent2.Add(familyBasicButton);
313 //Create family service style of button.
314 ButtonStyle familyServiceButtonStyle = new ButtonStyle
316 IsSelectable = false,
317 BackgroundImage = new Selector<string> { All = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_point_btn_normal_24c447.png" },
318 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
320 ImageShadow = new ImageShadow
322 Url = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png",
323 Border = new Rectangle(5, 5, 5, 5)
326 Overlay = new ImageViewStyle
328 ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
329 Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
332 Text = new TextLabelStyle
334 PointSize = new Selector<float?> { All = 20 },
335 HorizontalAlignment = HorizontalAlignment.Center,
336 VerticalAlignment = VerticalAlignment.Center,
337 WidthResizePolicy = ResizePolicyType.FillToParent,
338 HeightResizePolicy = ResizePolicyType.FillToParent,
340 TextColor = new Selector<Color>
342 Normal = new Color(1, 1, 1, 1),
343 Pressed = new Color(1, 1, 1, 0.7f),
344 Disabled = new Color(1, 1, 1, 0.4f),
346 Text = "FamilySeviceButton"
349 familyServiceButton = new Button(familyServiceButtonStyle);
350 familyServiceButton.Size = new Size(300, 80);
351 parent2.Add(familyServiceButton);
353 //Create family toggle style of button.
354 ButtonStyle familyToggleButtonStyle = new ButtonStyle
357 BackgroundImage = new Selector<string>
359 Normal = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_toggle_btn_normal_24c447.png",
360 Selected = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/rectangle_point_btn_normal_24c447.png",
362 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
364 ImageShadow = new ImageShadow
366 Url = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_shadow.png",
367 Border = new Rectangle(5, 5, 5, 5)
370 Overlay = new ImageViewStyle
372 ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/rectangle_btn_press_overlay.png", Other = "" },
373 Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
376 Text = new TextLabelStyle
378 PointSize = new Selector<float?> { All = 20 },
379 HorizontalAlignment = HorizontalAlignment.Center,
380 VerticalAlignment = VerticalAlignment.Center,
381 WidthResizePolicy = ResizePolicyType.FillToParent,
382 HeightResizePolicy = ResizePolicyType.FillToParent,
384 TextColor = new Selector<Color>
386 Normal = new Color(0.141f, 0.769f, 0.278f, 1),
387 Selected = new Color(1, 1, 1, 1),
389 Text = new Selector<string>
391 Normal = "Toggle Off",
392 Selected = "Toggle On"
396 familyToggleButton = new Button(familyToggleButtonStyle);
397 familyToggleButton.Size = new Size(300, 80);
398 parent2.Add(familyToggleButton);
400 //Create family oval style of button.
401 ButtonStyle familyOvalButtonStyle = new ButtonStyle
404 BackgroundImage = new Selector<string>
406 Normal = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_normal.png",
407 Selected = CommonResource.GetFHResourcePath() + "3. Button/[Button] App Primary Color/oval_toggle_btn_select_24c447.png",
409 BackgroundImageBorder = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
411 ImageShadow = new ImageShadow
413 Url = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_shadow.png",
414 Border = new Rectangle(5, 5, 5, 5)
417 Overlay = new ImageViewStyle
419 ResourceUrl = new Selector<string> { Pressed = CommonResource.GetFHResourcePath() + "3. Button/oval_toggle_btn_press_overlay.png", Other = "" },
420 Border = new Selector<Rectangle> { All = new Rectangle(5, 5, 5, 5) },
423 familyOvalButton = new Button(familyOvalButtonStyle);
424 familyOvalButton.Size = new Size(104, 104);
425 parent2.Add(familyOvalButton);
427 // Add three layout into root
433 private void Window_KeyEvent(object sender, Window.KeyEventArgs e)
435 if(e.Key.State == Key.StateType.Up)
437 switch(e.Key.KeyPressedName)
440 iconTextButton.IconRelativeOrientation = Button.IconOrientation.Right;
443 iconTextButton.IconRelativeOrientation = Button.IconOrientation.Top;
446 iconTextButton.IconRelativeOrientation = Button.IconOrientation.Bottom;
449 iconTextButton.IconRelativeOrientation = Button.IconOrientation.Left;
452 iconTextButton.Icon.Padding.Start = 50;
455 iconTextButton.Icon.Padding.End = 50;
458 iconTextButton.LayoutDirection = ViewLayoutDirectionType.RTL;
461 iconTextButton.LayoutDirection = ViewLayoutDirectionType.LTR;
467 public void Deactivate()
471 parent1.Remove(textButton);
472 textButton.Dispose();
474 parent1.Remove(utilityBasicButton);
475 utilityBasicButton.Dispose();
476 utilityBasicButton = null;
477 parent1.Remove(utilityServiceButton);
478 utilityServiceButton.Dispose();
479 utilityServiceButton = null;
480 parent1.Remove(utilityToggleButton);
481 utilityToggleButton.Dispose();
482 utilityToggleButton = null;
483 parent1.Remove(utilityOvalButton);
484 utilityOvalButton.Dispose();
485 utilityOvalButton = null;
487 parent1.Remove(familyBasicButton);
488 familyBasicButton.Dispose();
489 familyBasicButton = null;
490 parent1.Remove(familyServiceButton);
491 familyServiceButton.Dispose();
492 familyServiceButton = null;
493 parent1.Remove(familyToggleButton);
494 familyToggleButton.Dispose();
495 familyToggleButton = null;
496 parent1.Remove(familyOvalButton);
497 familyOvalButton.Dispose();
498 familyOvalButton = null;
500 parent3.Remove(iconTextButton);
501 iconTextButton.Dispose();
502 iconTextButton = null;
504 root.Remove(parent1);
508 root.Remove(parent2);
512 root.Remove(parent3);
516 NUIApplication.GetDefaultWindow().Remove(root);