Android入门(三):使用TextView、EditText 和Button接口组件
我使用的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接口组件的更多相关文章
- 【Android 应用开发】Android UI 设计之 TextView EditText 组件属性方法最详细解析
. 作者 :万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18964835 . TextView 相关类的继承结构 ...
- Android UI 设计之 TextView EditText 组件属性方法最详细解析
. 作者 :万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/18964835 . TextView 相关类的继承结构 ...
- Android入门(三)Activity-生命周期与启动模式
原文链接:http://www.orlion.ga/432/ 一.活动的生命周期 1.返回栈 Android中的活动是可以重叠的,我们每启动一个新的活动,就会覆盖在原活动之上,然后点击Back键会销毁 ...
- Android入门笔记(一)
第一部分,Android开发环境的搭建 1.去http://www.oracle.com/technetwork/java/javase/downloads/index.html下载最新版本jdk并安 ...
- android入门系列- TextView EditText Button ImageView 的简单应用
第一篇原创,其实自己就是一菜鸟,简单分享点基本知识吧.希望能有所帮助吧. TextView EditText Button ImageView 这几个控件可能是Android开发中最常用.最基本的几个 ...
- Android开发8:UI组件TextView,EditText,Button
版本:Android4.3 API18 学习整理:liuxinming TextView 概述 TextView直接继承了View(EditText.Button两个UI组件类的父类) TextVie ...
- Android入门:绑定本地服务
一.绑定服务介绍 前面文章中讲过一般的通过startService开启的服务,当访问者关闭时,服务仍然存在: 但是如果存在这样一种情况:访问者需要与服务进行通信,则我们需要将访问者与服务进行绑定: ...
- 【详细】Android入门到放弃篇-YES OR NO-》各种UI组件,布局管理器,单元Activity
问:达叔,你放弃了吗? 答:不,放弃是不可能的,丢了Android,你会心疼吗?如果别人把你丢掉,你是痛苦呢?还是痛苦呢?~ 引导语 有人说,爱上一个人是痛苦的,有人说,喜欢一个人是幸福的. 人与人之 ...
- Android入门(四):链接接口组件和程序代码
编写好layout中的接口组件之后,下一步就是编写控制接口组件的程序代码.上一章,我们使用了三种接口组件,在使用者输入性别和年龄之后点击“健康建议按钮”,程序会读取用户所填入的性别和年龄,然后显示判断 ...
随机推荐
- mate标签
<meta charset='utf-8'> <!-- 优先使用 IE 最新版本和 Chrome --> <meta http-equiv="X-UA-C ...
- 如何刷新或清除HttpURLConnection的连接缓存
项目需要定期与远程服务器同步数据,基于如下代码: URL url = new URL("http://test.com/sales/info"); connection = (Ht ...
- 8-9 MyBatis基础课
慕课网,'通过自动回复小机器人学习Mybatis',看了一半,没网了... Jsp+servlet+jdbc
- php如何防止图片盗用/盗链的两种方法
如今的互联网,采集网站非常多,很多网站都喜欢盗链/盗用别人网站的图片,这样不仅侵犯网权,还导致被盗链的网站消耗大量的流量,给服务器造成比较大的压力,本文章向大家介绍php如何防止图片盗用/盗链的两种方 ...
- 安装yii2时出错 Invalid Parameter – yii\base\InvalidParamException
最近composer安装yii2的时候页面报了这个错,应该是bower的前端资源位置改变的缘故! Invalid Parameter – yii\base\InvalidParamException ...
- multipart/form-data和application/x-www-form-urlencoded的区别
在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器时浏览器使用的编码类型. 下边是说明: application/x-www-form-urle ...
- 双系统Ubuntu分区扩容过程记录
本人电脑上安装了Win10 + Ubuntu 12.04双系统.前段时间因为在Ubuntu上做项目要安装一个比较大的软件,导致Ubuntu根分区的空间不够了.于是,从硬盘又分出来一部分空间,分给Ubu ...
- JS 对数组的常用处理
首先写游戏的时候,JSON字符串转成OBJECT的时候,希望做个数组随机排序的方法如下: //用Math.random()函数生成0~1之间的随机数与0.5比较,返回-1或1 function ran ...
- js框架设计1.4类型判断
这篇司徒大神介绍了很多js的 不靠谱类型判断.篇幅也是第一篇中最常的 ,经阅读后,以后一定要用框架的自带的类型判断,万万不可随便乱用js原生判断.
- Servlet 之 GenericServlet
我们都知道javaweb中servlet的三大组件 servlet filter listener 实现动态资源的 是可以继承 Servlet接口,或者集成GenericServlet .Http ...