前面我们学习了怎样创建我们第一个安卓工程,也了解了它基本运作,UI组件+事件处理代码,现在我们来学习Android的基本组件,组件就是你的手机中的按钮,文本框,图片等等,这些是最为基本的组件,看到这里是不是跃跃欲试了呢?现在我们开始认识它们。

所有的布局管理器,显示组件都是View类的子类。view类本身包含大量接口。

  • textView
  • <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" />
    可以定义字体长度颜色样式,具体自行查看API,首先我们在配置文件设置自己的文本样式,
 <style name="Mystyle" parent="android:Theme.Light">        <item name="android:textSize">45px</item>        <item name="android:textColor">#FFFF00</item>        <item name="android:autoLink">all</item>               <!--            Theme customizations available in newer API levels can go in            res/values-vXX/styles.xml, while customizations related to            backward-compatibility can go here.        -->    </style>

首先我们新建一个虚拟机用于运行我们创建的app


  • Button 是TextView的子类
  • 编辑框:EditText 也是TextView的子类
  • 单选按钮:RadioGroup

需要注意的是单选按钮RadioButton必须在RadioGroup中使用

 <RadioGroup        android:id="@+id/radioGroup1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentLeft="true"        android:layout_alignParentTop="true"        android:layout_marginLeft="63dp"        android:layout_marginTop="67dp" >        <RadioButton            android:id="@+id/radio0"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:checked="true"            android:text="男" />        <RadioButton            android:id="@+id/radio1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="女" />        <RadioButton            android:id="@+id/radio2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="其他" />    </RadioGroup>

效果如下:


用户选择后,可以获得选中按钮的ID,或者清空,或者设置要选中的按钮,具体可以参见方法。

  • 复选框 复选框不同于单选需要在RadioGroup中使用,它可以直接使用。
  • 下拉列表框:Spinner

首先自己新建一个xml文件定义:

<?xml version="1.0" encoding="utf-8"?><resources>    <string-array name="city">        <item >北京</item>        <item>上海</item>        <item>广州</item>    </string-array>    </resources>

然后:

这样运行出来的效果就是:







更多相关文章

  1. android Content provider 组件
  2. Android(安卓)SDK 4.0.3 开发环境配置及运行
  3. 译:Android的一些基础问题(一)
  4. Android开发入门_环境搭建
  5. android 删除的警告对话框
  6. android:stateNotNeeded="true"
  7. android音乐播放器开发_开篇
  8. Android(安卓)最火快速开发框架androidannotation简介
  9. 单选按钮(RadioButton)和复选框(CheckBox)的介绍与应用

随机推荐

  1. Android进行单元测试难在哪-part4
  2. android之官方下拉刷新组件SwipeRefreshL
  3. Android中点9图简易理解
  4. 【Android(安卓)Developers Training】 8
  5. android同步取得电池状态信息
  6. android 支付功能
  7. android中的多媒体应用MediaPlayer
  8. 为什么用Toast,而不是AlertDialog
  9. Android(安卓)Dialog用法总结
  10. Ubuntu Android(安卓)2.3的编译环境 Ubun