Android学习(2)---Android基本控件的学习
来源:互联网 发布:loho眼镜怎么样 知乎 编辑:程序博客网 时间:2024/05/06 00:53
内容概要
上次用markdown写了一篇,结果感觉排版是一塌糊涂,,,于是对这个东西的印象十分的不好,当然也可能是我不熟悉、不会用的原因,但是,暂且不使用这个MarkDown了,使用CSDN哪个普通的写出来的,样式应该更好看一些;
这篇博客主要用来记录Android基本组件的学习,4大核心组件就先不说了,Activity、Service、BroadcastReceiver、ContentProvider,intent也不说了,目前使用过的最多的也就是Activity了,还有intent,对于其他3个核心组件还没有写过代码,需要进一步的学习,本篇是跟着极客学院的视频来的,由页面布局开始,记录下常用控件的使用情况,将这些控件都放到一个小的demo项目中,由listView来包裹,点击展示各个控件的样式与基本使用。
控件列表
- RadioGroup
- CheckBox
- DatePicker
- TimePicker
- Spinner
- ProgressBar
- SeekBar
- RatingBar
- GridView
- ScorllView
- ProgressDialog
- Notification
- Gallery
- ImageSwitcher
- AutoCompleteTextView
- EditText
列表展示图:
DEMO源码:
百度网盘地址:BasicWeights
一些关键代码
- RadioGroup和CheckBox的关键属性:isChecked
- DatePickerDialog 和 TimePickerDialog 的使用代码
<span style="white-space:pre"></span>new DatePickerDialog(DatePickerAty.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) { datepickerbtn.setText(String.format("%d:%d:%d", year, monthOfYear, dayOfMonth)); } }, 2015, 12, 5).show();<span style="white-space:pre"></span>new TimePickerDialog(TimePickerAty.this, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker timePicker, int hourOfDay, int minite) { timepickerbtn.setText(String.format("%s:%s", timeFormat(hourOfDay), timeFormat(minite))); } }, 11, 34, true).show();3. Spinner关键方法:setAdapter
4. ProgressBar:setMax setProgress
5. SeekBar:setOnSeekBarChangeListener
6. ProgressDialog:
public class ProgressDialogAty extends Activity {private Button progressdialogshow;private ProgressDialog progressDialog;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.progressdialog_aty);progressdialogshow = (Button) findViewById(R.id.progressdialogshow);progressdialogshow.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {progressDialog = ProgressDialog.show(ProgressDialogAty.this,"加载","正在加载。。。");new Thread() {@Overridepublic void run() {try {Thread.sleep(3000);progressDialog.dismiss();} catch (InterruptedException e) {e.printStackTrace();}}}.start();}});}}
7. Notification:视频中还是使用的老的方法来实现的,我更喜欢新的方法,该淘汰的就淘汰吧
public class NotificationAty extends Activity { private Button notificationshow; private Notification n; private NotificationManager nm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notification_aty); nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationshow = (Button) findViewById(R.id.notificationshow); notificationshow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Notification n = new Notification(R.drawable.notification,"Ticker Text",System.currentTimeMillis()); // This method was removed in M (api 23). So if your compile SDK version is set to api 23+ you'll see this issue. // n.setLatestEventInfo(NotificationAty.this, "title", "content", PendingIntent.getActivity(NotificationAty.this, 1, getIntent(), 0)); // nm.notify(R.layout.aty_using_notification, n); // Intent intent = new Intent("com.rj.notitfications.SECACTIVITY"); PendingIntent pendingIntent = PendingIntent.getActivity(NotificationAty.this, 1, getIntent(), 0); Notification.Builder builder = new Notification.Builder(NotificationAty.this); builder.setAutoCancel(true); builder.setTicker("状态栏提示信息Tick"); builder.setContentTitle("通知标题"); builder.setContentText("通知内容"); builder.setSmallIcon(R.drawable.notification); // 这个地方设置的图片不知道为什么不起作用; builder.setContentIntent(pendingIntent); builder.setOngoing(true); // builder.setSubText("This is subtext..."); //API level 16 builder.setNumber(100); // builder.build(); n = builder.getNotification(); nm.notify(R.layout.notification_aty, n); } }); }}
总结
基本控件的使用暂且写这些吧,应该还有些控件没有涉及到,待到使用的时候再看应该也不是很迟,这些个控件的文档也还没有读过,还需要再看一下,总之有这么个小demo,必要的时候也好拿来抄一下。
edit by zhang.xx 2015年12月23日14:47:39
0 0
- Android学习(2)---Android基本控件的学习
- android学习五(android中基本控件的使用)
- Android学习笔记(一):基本控件
- android 学习笔记-基本控件
- Android基本控件TextView学习
- android基本控件学习网址
- Android学习笔记(十一) 基本控件的使用
- android学习笔记5--基本控件的介绍一
- Android 学习笔记7:基本控件
- Android 学习笔记8:基本控件
- Android开发学习之基本控件概览
- Android基本控件RadioGroup和RadioButton学习
- android开发学习笔记(2)android的基本介绍
- Android基本控件的使用(2)
- Android的基本控件(2)
- Android 基础控件的学习
- Android 的EditText控件学习
- Android ListView控件的学习
- 使用 Zend Opcache 加速 PHP
- JS插件开发之LightBox图片画廊
- java中如何反向输出字符串
- TP模板继承
- Android ContentProvider 分析与应用(一)使用ContentProvider
- Android学习(2)---Android基本控件的学习
- JSP生命周期和内置对象
- mysql截取字符串
- JS模拟土豆弹窗——链式运动
- 安卓Andriod ADB Interface驱动安装失败
- Objective-C加载方式讨论
- Echart 走势图随浏览器大小缩放
- Android之Activity详解
- iOS预览PDF文档 UIDocumentInteractionController