Android开发-之认识palette
Android开发中,Google工程师已经给我们封装好了很多的按钮,使得我们在开发中非常的方便和便捷。
那么今天就来认识一下常用的按钮,那么在之前的课程中我已经详细讲过了Button按钮,那么这里就不再重复了
Android开发-之监听button点击事件:http://www.cnblogs.com/xiao-chuan/p/6074075.html
一、常用按钮
1、按钮公共属性
按钮的公共属性包括:1)常用的样式属性
a、background
b、margin
c、……
2)宽高
a、width
b、height
3)大小
a、size
b、max(min)
c、……
4)文本显示内容
a、text
b、hint
5)唯一键ID
a、id
6)点击事件
2、TextView:
TextView:文本框
autoLink:文本的默认路径
<TextView
android:layout_width="match_parent"
android:layout_height="50sp"
android:text="中国移动:10086"
android:textSize="20sp"
android:autoLink="phone"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="50sp"
android:text="站长邮箱:10086@qq.com"
android:textSize="20sp"
android:autoLink="email"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="50sp"
android:text="有事找百度:http://www.baidu.com"
android:textSize="20sp"
android:autoLink="web"
/>
那么在这里呢,如果点击第一个 TextView默认效果就是电话啦,那么第二个第三个呢~~一下是实现的效果图,这里大家可以看到我并没有指定文本颜色,这里注意的是autoLink有默认的颜色啦!

3、EditText
EditText输入框
inputType:输入框输入的文本格式
<EditText
android:id="@+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入用户名"
android:textColor="@android:color/holo_red_light"
android:textSize="20sp"
android:inputType="text"
android:maxLength="12"
/> <EditText
android:id="@+id/userAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入年龄"
android:maxLength="3"
android:numeric="integer"
android:inputType="number"
/>
<EditText
android:id="@+id/userPwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"
android:maxLength="12"
android:password="true"
android:inputType="textPassword"
/>
<EditText
android:id="@+id/userAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入详细地址"
android:maxLength="500"
android:lines="3"
android:inputType="textMultiLine"
/>
inputType:
text:文本格式
textPassword:密码格式
number:数字格式
textMultiLink:地址栏格式
……
注:那么你输入的时候呢输入法也会自动切换输入的方式,以密码格式输入那么输入的内容是不可见的。
4、Bar
这里分为:
1)SeekBar:调度,就比如我们的音量,亮度等
2)RatingBar:选择,常见到的就是在电商网站上面的评论等
3)ProgressBar:加载、下载,加载图片,下载文件等
<TextView
android:id="@+id/showText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我是一个TextView"
android:textSize="20sp"
/>
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="50"
android:progress="20"
/>
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="1"
android:stepSize="1"
/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="10"
/>
<ProgressBar
android:id="@+id/progressBar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="10"
style="?android:attr/progressBarStyleLarge"
/>
<ProgressBar
android:id="@+id/progressBar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="10"
style="?android:attr/progressBarStyleHorizontal"
/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="开始"
android:onClick="doStart"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="结束"
android:onClick="doStop"
/>
</LinearLayout>
页面效果:

以下是为了让大家更加清楚它们的效果和区别:
private SeekBar sb;
private TextView showText;
private RatingBar rb;
private ProgressBar pb3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seek_bars); showText=(TextView)findViewById(R.id.showText);
sb=(SeekBar)findViewById(R.id.seekBar);
rb=(RatingBar)findViewById(R.id.ratingBar);
pb3=(ProgressBar)findViewById(R.id.progressBar3);
//为seekBar绑定事件
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
//改变showText字体大小
showText.setTextSize(progress);
}
}); rb.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
Toast.makeText(SeekBarsActivity.this, "你选择了"+rating+"星", 3000).show();
}
});
} //开始下载[注意:除了ProgressBar外,所有的UI都必须在UI主线程中操作]
boolean isRun=true;
public void doStart(View view) throws Exception{
isRun=true;
//构建一个执行进度条变化的子线程
new Thread(new Runnable() {
@Override
public void run() {
//耗时操作不能放在主线程中执行
while(isRun){
if(pb3.getProgress()<100){
pb3.setProgress(pb3.getProgress()+1);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}else{
isRun=false;
//最简单方法实现在多线程更新UI
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(SeekBarsActivity.this, "下载完毕",3000).show();
}
});
}
}
}
}).start();
}
//结束下载
public void doStop(View view){
isRun=false;
}
注意:
1)除了ProgressBar外,所有的UI都必须在UI主线程中操作,否则会报错
2)耗时操作不能放在主线程中执行,否则会报错
3)Google工程师让Android4.0以后的版本都不支持以上两点了,那么有人就要纠结了,那位了维护低版本,要怎么办~~自己想,很简单的问题!
5、Image与单选多选框
1)imageButton:图片按钮
2)imageView:图片视图
imageView与HTML5对比:
imageView:运行更流畅,在没有网络的情况下也可以使用。。
HTML5:运行时不够流畅,没有网就废了……但是优点在于页面更加美观,数据传输更加便捷。。
3)RadioButton:单选框,各元素是互斥的,只能选择一个,比如性别
4)CheckBox:多选按钮,可以选择多个,比如爱好
5)ToggleButton:单个提示按钮,比如开关
<RadioGroup android:id="@+id/rgsex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/sexOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
android:checked="true"
/>
<RadioButton
android:id="@+id/sexTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
/>
</RadioGroup>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="篮球"
/>
<CheckBox
android:id="@+id/cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="足球"
/>
<CheckBox
android:id="@+id/cb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="羽毛球"
/>
</LinearLayout> <ToggleButton
android:id="@+id/stateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="开灯"
android:textOff="关灯"
android:checked="true"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image001"
android:scaleType="fitXY"
android:maxWidth="120dp"
android:maxHeight="60dp"
android:adjustViewBounds="true"
android:onClick="getValues"
/>
效果如下:

ps:图片打码了是因为实在找不到合适的图片然后又不想给人家打广告又不得钱……
以下同样为了更加清楚它们的效果和区别:
private RadioGroup rg;
private CheckBox cb1,cb2,cb3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_buttons); cb1=(CheckBox)findViewById(R.id.cb1);
cb2=(CheckBox)findViewById(R.id.cb2);
cb3=(CheckBox)findViewById(R.id.cb3);
rg=(RadioGroup)findViewById(R.id.rgsex);
//监听单选按钮组事件
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton rb=(RadioButton)findViewById(checkedId);
Toast.makeText(ButtonsActivity.this, "你选择了:"+rb.getText().toString(), 3000).show();
}
});
} //取值[单选按钮|复选框]
public void getValues(View view){
//单选按钮
RadioButton rb=(RadioButton)findViewById(rg.getCheckedRadioButtonId());
StringBuffer sb=new StringBuffer();
sb.append("性别:"+rb.getText().toString()+"\n"); //复选框
sb.append("爱好:");
if(cb1.isChecked())
sb.append(cb1.getText().toString()+",");
if(cb2.isChecked())
sb.append(cb2.getText().toString()+",");
if(cb3.isChecked())
sb.append(cb3.getText().toString()+",");
Toast.makeText(this, sb.toString(), 5000).show();
}
PS:Google工程师都给我们封装好了,我们可以直接使用。我们也可以自己写一个底层的框架去实现这些按钮,相信大家在学习Java的时候这些按钮的实现都已经自己有写过了,其实Google工程师所封装的底层代码也是那样子实现的。只是说~谁那么无聊啊现成的不用!但是如果大家以后做Android框架开发的时候……就需要自己写了~在基础知识更新完了以后呢……就会涉及到比较高级的内容了哈哈哈哈……完全还没有准备!
二、总结
1、其实还有很多常用的以及一些不常用的,不管怎样都希望大家能够养成自学的习惯……到了公司更是如此!
2、Android框架的开发单纯的就是Java知识,所以跟Android开发没什么关系,但是又要对Android有很高的认知!
3、可以在Android页面中嵌套,但是要区分HTML5与Android palette之间的区别!
4、TextView和EditView的区别,其实很大……
5、palette要与相应的事件和业务逻辑一起使用才会真正的有意义,比如数据的传输~~在以后的课程中我会详细的讲解到。
Android开发-之认识palette的更多相关文章
- android 开发 对图片编码,并生成gif图片
demo场景: 将2张静态的png格式图片组合生成一个gif图片,间隔500毫秒,关键类:AnimatedGifEncoder 如需要解析gif获取每帧的图片,可参考上一篇博客:<android ...
- android 开发从入门到精通
Android-Tips This is an awesome list of tips for android. If you are a beginner, this list will be t ...
- 【转】Android开发笔记(序)写在前面的目录
原文:http://blog.csdn.net/aqi00/article/details/50012511 知识点分类 一方面写写自己走过的弯路掉进去的坑,避免以后再犯:另一方面希望通过分享自己的经 ...
- 2015年Android开发新技术盘点
又到年末. 利用中午的时间,汇总盘点一下今年Android开发方面的新技术.感觉如今Android开发没有曾经那么纯粹了,出现了非常多新的开发模式. 2015年影响比較普遍的新技术应该就是Materi ...
- 50、转自知乎上android开发相见恨晚的接口
原文链接:http://www.zhihu.com/question/33636939 程序员软件开发Android 开发JavaAndroid修改 Android开发中,有哪些让你觉得相 ...
- Android开发常用开源框架:图片处理
https://blog.csdn.net/SGQ_CSDN/article/details/79910709 Android开发常用开源框架:图片处理 框架名称 功能描述 Android Unive ...
- Android学习探索之Java 8 在Android 开发中的应用
前言: Java 8推出已经将近2年多了,引入很多革命性变化,加入了函数式编程的特征,使基于行为的编程成为可能,同时减化了各种设计模式的实现方式,是Java有史以来最重要的更新.但是Android上, ...
- Android 开发一定要看的15个实战项目
前言: 虽说网上有太多的Android课程,但是大多都是视频,有Android在线开发环境的几乎没有,但是对于学习Android的人来说拥有在线的Android开发环境是非常好的,可以随时动手操作学习 ...
- Android开发学习之路-关于Exception
Exception在Java中是表示异常的一个类.它是Throwable的子类. 而Exception的子类RuntimeException是一个特殊的异常类,在代码中不需要对此类进行throw,而是 ...
随机推荐
- [转]oracle 分析函数over
oracle 分析函数over 分析函数(OVER) 目录: =============================================== 1.Oracle分析函数简介 2. O ...
- JAVA集合类型详解
一.前言 作为java面试的常客[集合类型]是永恒的话题:在开发中,主要了解具体的使用,没有太多的去关注具体的理论说明,掌握那几种常用的集合类型貌似也就够使用了:导致这一些集合类型的理论有可能经常的忘 ...
- 深度学习框架搭建之最新版Python及最新版numpy安装
这两天为了搭载深度学习的Python架构花了不少功夫,但是Theano对Python以及nunpy的版本都有限制,所以只能选用版本较新的python和nunpy以确保不过时.但是最新版Python和最 ...
- 前端小知识~~关于css3新增知识~~归纳总结
1.新增选择器 E:nth-last-child(n) E:nth-of-type(n) E:nth-last-of-type(n) E:last-child E:first-of-type E:on ...
- Torch7学习笔记(三)Sequencialization
1.序列化 Torch提供4种高级方法来序列化或者反序列化任意Lua/Torch对象.这些方法都是从File对象抽象出来的,为了方便操作而创建. 前两种方法用来从文件序列化或者反序列化的: torch ...
- spring动态代理
接下来我们来体会下动态代理带给我们的便利 package aop006; public interface Girl { public void KFC(String datetime); publi ...
- gulp-less解决遇到错误停止执行task
来龙去脉 在用less+gulp开发时,有时候代码还没写完整,不小心保存了一下,然后gulp就开始执行gulp-less的task. 但是代码是有问题的,这时候会输出一个Potentially unh ...
- PHP 之 CURL 模拟登陆并获取数据
1.CURL模拟登陆的流程和步骤 2.tempnam 创建一个临时文件 3.使用CURL模拟登陆到PHP100论坛 <?php $cookie_file = tempnam('./temp',' ...
- ES6的promise对象应该这样用
ES6修补了一位Js修真者诸多的遗憾. 曾几何时,我这个小白从js非阻塞特性的坑中爬出来,当我经历了一些回调丑陋的写法和优化的尝试之后,我深深觉得js对于多线程阻塞式的开发语言而言,可能有着其太明显的 ...
- JDBC的连接和增删改和查找
package Test2;import java.sql.*;import java.sql.DriverManager;import java.sql.SQLException;public cl ...