Buttons 示例介绍了定义Button,ToggleButton的基本方法。本例在/res/layout/buttons_1.xml 定义如下:

<!– Regular sized buttons –>
<Button android:id=”@+id/button_normal”
android:text=”@string/buttons_1_normal”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

<!– Small buttons –>
<Button android:id=”@+id/button_small”
style=”?android:attr/buttonStyleSmall”
android:text=”@string/buttons_1_small”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

<ToggleButton android:id=”@+id/button_toggle”
android:text=”@string/buttons_1_toggle”
android:textOn=”Open”
android:textOff=”Close”

android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

定义button 不指定任何风格时,Android以正常大小显示Button,

风格 ?android:attr/buttonStyleSmall 以紧凑风格显示Button。

在引用Style 属性值时, 使用“?” 而非”@” 来指定所需风格属性,格式如下:

?[<package_name>:][<resource_type>/]<resource_name>

其中resource_type部分可选,因此 本例也可以使用如下定义:

style=”?android:buttonStyleSmall”

ToggleButton 使用button 形式定义两种状态,比如Open,Close。缺省文本为ON, OFF, 可以使用属性textOn,textOff 重新定义文字。

Android ApiDemos示例解析(105):Views->Buttons_第1张图片

更多相关文章

  1. Android 动画系列之自定义补间动画
  2. 【自定义控件系列四】android绘制实战(一)通过Canvas+Path+Paint
  3. 强烈推荐:Android史上最强大的自定义任务软件Tasker
  4. android 自定义相机 取矩形内内容 注意事项
  5. Android 属性动画(Property Animation)介绍

随机推荐

  1. Android System.gc()与Runtime.getRuntim
  2. Android 配置 之 AndroidManifest.xml 出
  3. ubuntu 12.04 下安装android编译环境
  4. cordova打包android apk
  5. Android输入法的显示与隐藏
  6. Android ImageView去掉周围的白边
  7. 关于一个android工程同时使用多个工程库,
  8. 从源码一次彻底理解Android的消息机制
  9. Android Google应用移植时包依赖关系
  10. Android积木之图片的生成和保存