我使用的IDE是Android Studio 2.1,虽然使用Eclipse也可以进行Android的开发,但是网上的大神大都推荐Android Studio,愿意了解的朋友可以参考知乎上关于Android Studio 和 Eclipse的讨论(网页链接:https://www.zhihu.com/question/21534929)。

  今天是正式学习Android开发的第一课,我从一些基本的接口组件的使用开始讲解,文中涉及到的一些接口组件我不会详细的去介绍,具体的介绍可以在网上搜索一下,这样也是为了避免语言的琐碎,提高学习效率。

1.TextView接口组件

    范例:<TextView android:id="@+id/txtRsult"

             android:layout_width="fill_parent"

             android:layout_height="wrap_content"

             android:text="程序运行结果"

        />

  以上程序代码的功能是增加一个名为txtRsult的TextView组件,该组件的功能是显示信息,用户无法编辑其中的文字。它的宽度设置为fill_parent,也就是填满它所在的外框,高度设置为wrap_content,也就是由文字的高度来决定,组件中会显示“程序运行结果”这个字符串。除了上面所用到属性,还有很多其他的属性,可以自行在网上搜索一下。

2.EditText接口组件

    范例:<EditText android:id="@+id/edtSex"

             android:layout_width="fill_parent"

                 android:layout_height="wrap_content"

             android:inputType="text"

             android:text=""

        />

  以上程序代码的功能是增加一个名为edtSex的EditText组件,该组件的功能是输入一段文件,再让程序读取该字符串。其中我重点介绍一下android:inputType属性,它是用来限制这个组件可以接受的字符类型,text代表任何字符都可以被接受,如果设置成number则只能输入0~9的数字字符。

3.Button接口组件

    范例:<Button android:id="@+id/btnDoSug"

               android:layout_width="fill_parent"

                   android:layout_height="wrap_content"

            android:text="运行"

        />

  接下来我们将上面所学习的三个接口组件进行整合,程序代码如下:

       <?xml version="1.0" encoding="utf-8"?>

       <LinearLayout

             android:orientation="vertical"

               android:layout_width="fill_parent"

                   android:layout_height="wrap_content" 

          >

        <TextView android:id="@+id/txtRsult"

             android:layout_width="fill_parent"

             android:layout_height="wrap_content"

             android:text="性别"

          />

         <EditText android:id="@+id/edtSex"

             android:layout_width="fill_parent"

                 android:layout_height="wrap_content"

             android:inputType="text"

             android:text=""

          />

          <TextView android:id="@+id/txtRsult"

             android:layout_width="fill_parent"

             android:layout_height="wrap_content"

             android:text="年龄"

          />   

          <EditText android:id="@+id/edtSex"

             android:layout_width="fill_parent"

                 android:layout_height="wrap_content"

             android:inputType="text"

             android:text=""

          /> 

          <Button android:id="@+id/btnDoSug"

               android:layout_width="fill_parent"

                   android:layout_height="wrap_content"

            android:text="健康建议"

              />   

          <TextView android:id="@+id/txtRsult"

             android:layout_width="fill_parent"

             android:layout_height="wrap_content"

             android:text="结果"

          /> 

         <LinearLayout/>

  特别说明一下,<LinearLayout>卷标是指定接口组件采线性顺序排列。它是一种接口组件的编排模式。

  

Android入门(三):使用TextView、EditText 和Button接口组件的更多相关文章

  1. 【Android 应用开发】Android UI 设计之 TextView EditText 组件属性方法最详细解析

    . 作者 :万境绝尘  转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18964835 . TextView 相关类的继承结构 ...

  2. Android UI 设计之 TextView EditText 组件属性方法最详细解析

    . 作者 :万境绝尘  转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18964835 . TextView 相关类的继承结构 ...

  3. Android入门(三)Activity-生命周期与启动模式

    原文链接:http://www.orlion.ga/432/ 一.活动的生命周期 1.返回栈 Android中的活动是可以重叠的,我们每启动一个新的活动,就会覆盖在原活动之上,然后点击Back键会销毁 ...

  4. Android入门笔记(一)

    第一部分,Android开发环境的搭建 1.去http://www.oracle.com/technetwork/java/javase/downloads/index.html下载最新版本jdk并安 ...

  5. android入门系列- TextView EditText Button ImageView 的简单应用

    第一篇原创,其实自己就是一菜鸟,简单分享点基本知识吧.希望能有所帮助吧. TextView EditText Button ImageView 这几个控件可能是Android开发中最常用.最基本的几个 ...

  6. Android开发8:UI组件TextView,EditText,Button

    版本:Android4.3 API18 学习整理:liuxinming TextView 概述 TextView直接继承了View(EditText.Button两个UI组件类的父类) TextVie ...

  7. Android入门:绑定本地服务

    一.绑定服务介绍   前面文章中讲过一般的通过startService开启的服务,当访问者关闭时,服务仍然存在: 但是如果存在这样一种情况:访问者需要与服务进行通信,则我们需要将访问者与服务进行绑定: ...

  8. 【详细】Android入门到放弃篇-YES OR NO-》各种UI组件,布局管理器,单元Activity

    问:达叔,你放弃了吗? 答:不,放弃是不可能的,丢了Android,你会心疼吗?如果别人把你丢掉,你是痛苦呢?还是痛苦呢?~ 引导语 有人说,爱上一个人是痛苦的,有人说,喜欢一个人是幸福的. 人与人之 ...

  9. Android入门(四):链接接口组件和程序代码

    编写好layout中的接口组件之后,下一步就是编写控制接口组件的程序代码.上一章,我们使用了三种接口组件,在使用者输入性别和年龄之后点击“健康建议按钮”,程序会读取用户所填入的性别和年龄,然后显示判断 ...

随机推荐

  1. 基于iSCSI的SQL Server 2012群集测试(一)--SQL群集安装

    一.测试需求介绍与准备 公司计划服务器迁移过程计划同时上线SQL Server2012,引入SQL Server2012群集提高高可用性,需要对SQL Server2012群集技术进行研究.测试,确保 ...

  2. css3的基本样式

    一.css3字体(@font-face) 二.css3动画 三.css3多列 四.CSS3 outline-offset 属性 五.CSS3 resize 属性

  3. Apache限制某个目录下的PHP文件没有执行权限

    为了安全期间,有时我们需要限制网站下的某些目录对于php脚本不能执行. 有两种方法可以参考: 1.  使用.htaccess 文件限制 在要限制php执行的目录下,创建.htaccess文件,加入内容 ...

  4. Android-做个性化的进度条

    1.案例效果图 2.准备素材                                progress1.png(78*78)              progress2.png(78*78) ...

  5. RobotFrameWork(六)控制流之For循环

    转自: http://blog.csdn.net/mengfanbo123/article/details/9033645 For循环 函数结构范例: :For 变量  IN  序列(or 列表) 关 ...

  6. mysql数据库视图连接出现2003····错误

    MySQL利用视图工具连接数据库时出现2003····错误                                                  原因:MySQL的服务没有开启 解决步骤: ...

  7. 删除安装的 cocoapods 的缓存方法

    清除 Cocoapods 本地缓存 特殊情况下,由于网络或者别的原因,通过 cocoapods 下载的文件可能会有问题.这时候可以删除 Cocoapods 的缓存(~/Library/Caches/C ...

  8. Java中的位运算

    昨天去面试的时候做到了一道Java的位运算题目,发现有个运算符不懂:">>>",今天特地查了一下,并小结一下常见的位运算符号: ~  按位非(NOT)(一元运算) ...

  9. WebConfig配置

    安全配置示例 https://msdn.microsoft.com/zh-cn/magazine/gg309184.aspx

  10. C++ 的二进制语法与语义

    /* 转载请注明出处:http://www.cnblogs.com/Martinium/p/binary_literal.html */ 二进制的语法 C/C++ 默认数字使用十进制,八进制使用前缀 ...