我使用的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. 图解JVM的Class文件格式(详细版)

          了解JAVA的Class文件结构有助于掌握JAVA语言的底层运行机制,我在学习的过程中会不断的与ELF文件格式作对比(当然他们的复杂程度.格式相去甚远,比如可执行ELF的符号表解析在静态链 ...

  2. 面试题目——《CC150》栈与队列

    面试题3.1:描述如何只用一个数组来实现三个栈. 方法1:固定分割 方法2:弹性分割(较难) package cc150; public class ArrayStack { public stati ...

  3. maven install时报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile

    首先检查父项目,子项目的jdk版本是否一致,编码格式是否一致我的问题就错在了编码格式上,父项目用的是UTF-8,子项目新建的,默认GBK这时,使用maven install命令出错 提示:[INFO] ...

  4. 【总结2】PhpStorm利用XDebug调试PHP技巧

    在写完 [总结1]PhpStorm配置XDebug(远程)调试PHP 后,发现PhpStorm调试PHP还有一个技巧,如下图所示: 路径:File -> Settings -> Langu ...

  5. position:fixed失效

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Codeforces 696 C. PLEASE

    Description 三个杯子,一开始钥匙在中间,每次等概率的选择两边的两个,与中间的交换,问第 \(n\) 次选择中间的杯子是钥匙的概率是多少. \(n=\sum_{i=1}^{k} a_i,a_ ...

  7. phpstorm的使用教程

    1.设置行号:file->settings->Editor->Appearance->Show line numbers 2.设置字体和背景 :file->setting ...

  8. ecshop二次开发常用文件位置

    语言包修改: /language/zh_cn/admin/common.php 商品详情页模板: /themes/**/goods.dwt  (最下方有changePrice() 点选属性或改变数量时 ...

  9. 【GoLang】golang 的精髓--流水线,对现实世界的完美模拟

    直接上代码: package main import ( "fmt" "runtime" "strconv" "sync" ...

  10. 【ASP.NET】利用Nuget打包package——GUI方式

    GUI方式 通过GUI的方式,可以下载如下的软件 NuGetPackageExplorer   打包dll 1.打开软件,在Package Content处点击右键 ,选择Add Lib 2.在lib ...