Buttons

Onyx提供了种类丰富的button。本文将介绍最常用的几类button。

onyx.Button

onyx.Button直接从enyo.button继承而来,提供同样的基本功能。

{kind: "onyx.Toolbar", components: [

{kind: "enyo.Button", content: "enyo.Button"},

{kind: "onyx.Button", content: "onyx.Button"}

]}

当点击onyx.Button时会触发ontap事件,你可以指定处理方法来处理该事件。

{kind: "onyx.Button", content: "tap me", ontap: "buttonTapped"},

...

buttonTapped: function(inSender, inEvent) {

// respond to the tap event

}

另外,你可以指定圆角、背景颜色或应用onyx的内置button样式来定制button的外形:

{kind: "onyx.Toolbar", components: [

{kind: "onyx.Button", content: "tap me"},

{kind: "onyx.Button", content: "purple", style: "background-color: purple; color: #F1F1F1;"},

{kind: "onyx.Button", content: "yes", classes: "onyx-affirmative"},

{kind: "onyx.Button", content: "no", classes: "onyx-negative"},

{kind: "onyx.Button", content: "onyx-blue", classes: "onyx-blue"}

]}

你也可以在button中放一个image,使用或省略文字,如:

{kind: "onyx.Button", ontap:"buttonTapped", components: [

{kind: "onyx.Icon", src: "https://github.com/enyojs/enyo/wiki/assets/fish_bowl.png"}

]}

{kind: "onyx.Button", ontap:"buttonTapped", components: [

{tag: "img", attributes: {src: "https://github.com/enyojs/enyo/wiki/assets/fish_bowl.png"}},

{content: "Go Fish"}

]}

onyx.IconButton

类似的效果也可以使用onyx.IconButton实现,它是onyx.Icon的一个子类。例:

{kind: "onyx.IconButton", src: "assets/my_icon.png"}

生成一个像button的icon,但是不显示和button连在一起的矩形阴影。

使用onyx.Icon生成一个既有文字又有图片的button:

{kind: "onyx.Button", ontap: "buttonTap", components: [

{kind: "onyx.Icon", src: "assets/my_icon.png"},

{content: "tap me"}

]}

onyx.IconButton和onyx.Button的一个不同点是IconButton中image的src属性假定是32*64,button的上半部分在正常状态时显示,下半部分在active时显示。(By contrast, when you activate an onyx.Button that contains an image, the state change is reflected in the button's background, but not in the image itself.)

onyx.RadioButton

In Enyo 2, an onyx.RadioButton is an enyo.Button designed to go inside an onyx.RadioGroup (a horizontally-oriented group of buttons in which tapping on one button will release any previously-tapped button).

例:

enyo.kind({

name: "RadioGroupSample",

kind: "Control",

components: [

{kind: "onyx.RadioGroup", onActivate: "radioActivated", components: [

{content: "Alpha"},

{content: "Beta"},

{content: "Gamma"}

]},

{name: "statusText", content: "Please make a selection"}

],

radioActivated: function(inSender, inEvent) {

if (inEvent.originator.getActive()) {

this.$.statusText.setContent("Current selection: " +

inEvent.originator.getContent());

}

}

});

注意有一个处理整个radio group的方法。当button tapped时,我们可以使用inEvent.originator来确定事件源。我们不需要显示声明radio button的类型。当一个control添加到onyx.RadioGroup,它的kind默认为onyx.RadioButton。(你可以设置radiogroup的defaultKind属性来改变这一默认行为)。

onyx.ToggleButton

onyx.ToggleButton看起来像两个状态的切换开关。每当点击toggle button它都会切换值并触发onChange事件。

{kind: "onyx.ToggleButton", onContent: "foo", offContent: "bar", onChange: "buttonToggle"},

...

buttonToggle: function(inSender, inEvent) {

this.log("Toggled to value " + inEvent.value);

}

你可以使用CSS设置背景颜色来定制toggle button的on状态的外观。

{kind: "onyx.ToggleButton", style: "background-color: #35A8EE;"}

最后,你可以调用getValue方法来索引button的值(返回一个boolean值):

queryToggleValue: function() {

return this.$.toggleButton.getValue();

}

转载于:https://www.cnblogs.com/waimai/archive/2013/02/25/2932780.html

enyo官方开发入门教程翻译一Controls之Buttons相关推荐

  1. enyo官方开发入门教程翻译一Layout之Fittables

    Fittables Fittable包帮助你创建布局更合理的使用可用空间(app都有这样的布局需求,但使用以前的web技术很难做到这一点).个人观点,现在移动Web开发框架中有很多都支持自适应布局,如 ...

  2. IntelliJ IDEA开发入门教程

    IntelliJ IDEA开发入门教程 本系列教程从 IntelliJ IDEA 的安装.卸载.软件设置.项目配置等各个方面进行讲解.通过本系列教程的学习,也希望你能爱上 IntelliJ IDEA, ...

  3. 【Arduino】开发入门教程【一】什么是Arduino

    Arduino Arduino 是一款便捷灵活.方便上手的开源电子原型平台,包含硬件(各种型号的arduino板)和软件(arduino IDE).它适用于艺术家.设计师.爱好者和对于"互动 ...

  4. Arduino可穿戴开发入门教程LilyPad介绍

    Arduino可穿戴开发入门教程LilyPad介绍 Arduino输出模块 LilyPad官方共提供了4种输出模块,他们分别是单色LED模块(图1.5).三色LED模块(图1.6).蜂鸣器模块(图1. ...

  5. Arduino可穿戴开发入门教程(大学霸内部资料)

    Arduino可穿戴开发入门教程(大学霸内部资料) 试读下载地址:链接:http://pan.baidu.com/s/1mg9To28 密码:z5v8 介绍:Arduino可穿戴开发入门教程(大学霸内 ...

  6. ActiveReports 报表控件官方中文入门教程 (2)-创建、数据源、浏览以及发布

    ActiveReports 报表控件官方中文入门教程 (2)-创建.数据源.浏览以及发布 原文:ActiveReports 报表控件官方中文入门教程 (2)-创建.数据源.浏览以及发布 本篇文章将阐述 ...

  7. UWP开发入门教程备忘

    UWP-01~03 略~ UWP-04 - 什么是XAML? XAML - 遵循XML语法,XAML实际上是在创建类的实例,并给它们设定属性值,用于定义UI UWP-05 - 类型转换器 类型转换器 ...

  8. 敏捷开发入门教程-----摘抄

    敏捷开发入门教程 作者: 阮一峰 日期: 2019年3月 6日 感谢 腾讯课堂NEXT学院 赞助本站,官方小程序课程 正在招生. 敏捷开发(agile development)是非常流行的软件开发方法 ...

  9. Arduino可穿戴开发入门教程Windows平台下安装Arduino IDE

    Arduino可穿戴开发入门教程Windows平台下安装Arduino IDE Windows平台下安装Arduino IDE Windows操作系统下可以使用安装向导和压缩包形式安装.下面详细讲解这 ...

最新文章

  1. Android10桌面启动器高级版,SONY Xperia launcher-索尼Z5桌面启动器下载10.0.A.0安卓最新版-西西软件下载...
  2. Boost:自定义小矢量的测试程序
  3. CSS清除默认样式,聪明人已经收藏了!
  4. 1893. 检查是否区域内所有整数都被覆盖
  5. C++将地址转换为字符串
  6. NumPy Beginner's Guide 2e 带注释源码 二、NumPy 基础入门
  7. ADF12C+GLASSFISH4.1配置数据源
  8. 计算机大学英语值最高的3项,计算机等级考试一级B上机试题:Windows字处理
  9. mysql+vs检测不到_VS2017 + EF + MySQL 我使用过程中遇到的坑
  10. php如何转换大小写,PHP转换大小写教程基础
  11. static 在C/C++中的用法总结
  12. Kindle Touch 5.3.7上手使用指南
  13. PS初学者(非设计专业人士)的碎碎念
  14. 亚信安全发现勒索软件新变种Word文档成为导火索
  15. com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
  16. VMware虚拟机win10系统桥接模式连不上网
  17. dependency check工具的使用
  18. JavaFx教程-01初识javaFX
  19. 狂神Vue笔记,后端必须了解的前端知识
  20. 笔记本电脑都有光驱吗?

热门文章

  1. 国家自然基金标书申报体会
  2. BZOJ-1013-球形空间产生器sphere
  3. BZOJ 4898 Luogu P3778 [APIO2017]商旅 (分数规划、最短路)
  4. c语言复制的代码不能运行,刚学C语言,在Linux下写的代码能正常编译,复制到VC下就无法运行...
  5. java中class_Java中Class对象详解
  6. python 下载文件 限速-Python网络爬虫---scrapy通用爬虫及反爬技巧
  7. 调整亮度_【紫墨手机摄影课堂】图片调整
  8. c mssql mysql_mssql与mysql 数据迁移
  9. python word 表格 框线_python设置表格边框的具体方法
  10. 二进制、字节、int范围、编码