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,而是 ...
随机推荐
- [JSOI2008]完美的对称 题解
题目大意: 首先我们给定一点A以及对称中心S,点A'是点A以S为对称中心形成的像点,即点S是线段AA'的对称中心. 点阵组(X)以S为中心的像点是由每个点的像点组成的点阵组.X是用来产生对称中心S的, ...
- Shader实例:NGUI图集中的UISprite正确使用Shader的方法
效果: 变灰,过滤,流光 都是UI上常用效果. 比如: 1.按钮禁用时,变灰. 2.一张Icon要应付圆形背景框,又要应付矩形背景框.就要使用过滤的方式来裁剪. 避免了美术提供两张icon的麻烦,又节 ...
- sass sourcemap详细使用
新发布的Sass 3.3版本,将Source Maps正式纳入了Sass中.这也成为Sass新版本的一大亮点,一大新功能.让广大Sass爱好者可以直接在浏览器中更容易调试自己的代码和Debug相关操作 ...
- _MSC_VER详细介绍
_MSC_VER详细介绍 转自:http://www.cnblogs.com/braver/articles/2064817.html _MSC_VER是微软的预编译控制. _MSC_VER可以分解为 ...
- c# 局域网文件传输实例
一个基于c#的点对点局域网文件传输小案例,运行效果截图 //界面窗体 using System;using System.Collections.Generic;using System.Compon ...
- 编写base64图片文件
base64编码代替css背景图片在网站上应用是很广泛的,例如:loading gif图片,天猫加载时那只猫等等. 因为base64图片可以减少http请求,所以我们经常会把不经常改动的,独立的,尺寸 ...
- java分享第十七天-03(封装操作mysql类)
JAVA操作mysql所需jar包:mysql-connector-java.jar代码: import java.sql.*; import java.util.ArrayList; import ...
- Spring的三种通过XML实现DataSource注入方式
Spring的三种通过XML实现DataSource注入方式: 1.使用Spring自带的DriverManagerDataSource 2.使用DBCP连接池 3.使用Tomcat提供的JNDI
- checkbox选中状态不被改变
让它的状态只能看不能改变,加上onclick="return false;". 也可以disabled="true";但是这个颜色变淡了; <input ...
- String.Format 格式说明
C#格式化数值结果表 字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0 ...