Android应用之基本的组件(一)
请大家伙多多指教:
请关注:ailiandeziwei
总的页面:
注意:按钮间方法的改变需要: android:onClick="clearNoti" 添加相应的方法即可
1.点击状态栏按钮时:
public void Notification(View v){
showNotification("亲来短信了","5557","我喜欢你", R.drawable.ic_launcher, R.drawable.ic_launcher);
}
public void showNotification(String tickerText,String contentTitle,String contentText ,int iconId,int notiId ){
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//创建一个Notification
Notification notification = new Notification();
//设置发出信息的内容
notification.icon =iconId;
//设置发出的信息
notification.tickerText=tickerText;
//设置发出通知的时间
notification.when=System.currentTimeMillis();
//设置显示通知的默认的发声或者振动,Light效果
notification.defaults=Notification.DEFAULT_VIBRATE;//振动的效果
//3步: PendingIntent Android系统负责维护
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,getIntent() ,0);
//Notification notification = new Notification(R.drawable.ic_launcher, "有新的消息", System.currentTimeMillis());
//4步;设置更加详细的信息
notification.setLatestEventInfo(this, contentTitle,contentText,pendingIntent);
//5步:使用notificationManager对象的notify方法 显示Notification消息 需要制定 Notification的标识
notificationManager.notify(notiId,notification);
} 效果图:
2.点击清楚状态按钮时:
//清除的操作
public void clearNoti(View v ){
notificationManager.cancelAll();//清除所有
}
3点击创建对对话框时: public void DiaLog(){
AlertDialog alertDialog = new AlertDialog.Builder(this)
.setIcon(R.drawable.mw)
.setTitle("DiaLog").setMessage("是否创建文件")
.setPositiveButton("确认",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new AlertDialog.Builder(MainActivity.this).setMessage("您点击了确认按钮,文件已经被创建").show();
}
})
.setNegativeButton("取消",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new AlertDialog.Builder(MainActivity.this)
.setMessage("您已经选择了取消的按钮,该文件不会被创建").create()
.show();
}
}).show();
}
4。点击简单列表对话框
public void Simplelistdialog(View v){
final String items[] = {"java","php","3g",".net"};
AlertDialog alertDialog = new AlertDialog.Builder(this)
.setTitle("简单列表对话框").setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "亲,你喜欢的科目是:"+items[which],Toast.LENGTH_LONG).show();
}
}).show();
}
5.点击单选列表对话框
public void Radiolistdialog(View v){
final String items[] = {"java","php","3g",".net"};
AlertDialog alertDialog = new AlertDialog.Builder(this).setTitle("单选列表对话框")
//.setSingleChoiceItems(items, checkedItem, listener)
//.setSingleChoiceItems(itemsId, checkedItem, listener)
//.setSingleChoiceItems(cursor, checkedItem, labelColumn, listener) labelColumn如果数据源是数据集
//数据集中的某一列会作为列表对话框的数据加载的列表框中,该参数表示该列的名称(字段名称)
.setSingleChoiceItems(items,1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "亲,你喜欢的科目是:"+items[which],Toast.LENGTH_LONG).show();
}
}).show();
}
7.点击多选列表对话框
public void Multiselectlistdialog(View v){
final String items[]={"Java","PHP","3G",".NET"};
new AlertDialog.Builder(this).setTitle("多选列表对话框")
//.setMultiChoiceItems(itemsId, checkedItems, listener)
//.setMultiChoiceItems(cursor, isCheckedColumn, labelColumn, listener)
.setMultiChoiceItems(items, new boolean[]{false,true,true,false}, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if(isChecked){
Toast.makeText(getApplicationContext(), "亲,你选中的科目是:"+items[which], Toast.LENGTH_LONG).show();
}
}
}).setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "亲,你喜欢的科目有:", Toast.LENGTH_LONG).show();
}
}).show();
}
8.点击进度条
public void ProgressDialog(View v){
handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch(msg.what){
case PRO:
if(PRO>=MAX_PROGRESS){
//重新设置
progress=0;
progressDialog.dismiss();//销毁对话框
}else{
progress++;
progressDialog.incrementProgressBy(1);
//延迟发送消息
handler.sendEmptyMessageDelayed(PRO,100);
}
break;
default:
break;
}
}
};
progressDialog = new ProgressDialog(this);
progressDialog.setIcon(R.drawable.mw);
progressDialog.setTitle("正在处理数据......");
progressDialog.setMessage("请稍后.....");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); //设置进度条对话框 (水平,旋体)
//设置最大值
progressDialog.setMax(MAX_PROGRESS);
progressDialog.setButton("暂停",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.removeMessages(PRO);
}
});
progressDialog.setButton2("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//删除消息队列
handler.removeMessages(PRO);
//恢复进度初始值
progress=0;
progressDialog.setProgress(progress);
}
});
//显示
progressDialog.show();
//必须设置到show之后,show之前可能bug
progress = (progress>0) ?progress:0;
progressDialog.setProgress(progress);
//线程
handler.sendEmptyMessage(PRO);
}
还有一种效果是:
9.点击自定义表对话框
public void MyDialog(View v){
LayoutInflater layoutInflater = getLayoutInflater();
View view = layoutInflater.inflate(R.layout.activity_main, null); //R.layout.activty_main自定义的布局文件这里可以是自己随意定义的
new AlertDialog.Builder(this).setView(view).setTitle("自定义的对话框").setPositiveButton("确认按钮", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//处理
}
}).show();
}
Android应用之基本的组件(一)的更多相关文章
- 收藏的Android很好用的组件或者框架。
收藏的Android很好用的组件或者框架. android框架 先说两个站点: http://www.androidviews.net/ 非常好的国外开源码站,就是訪问速度有点慢啊 http://w ...
- Android图表日历控件组件
1.图表引擎 - AChartEngine AChartEngine是一款基于Android的图表绘制引擎,它为Android开发人员提供了非常多有用的图表绘制工具类,假设你须要在Android应用中 ...
- 支付宝 Android 版使用的开源组件
支付宝 Android 版使用的开源组件 前言: 花了点时间整理了 支付宝 Android 客户端使用的开源组件,给需要的同学.在你不知道用什么开源框架的时候可以作下参考,毕竟支付宝是阿里的重量级产品 ...
- Android 开发:由模块化到组件化(一)
在Android SDK一文中,我们谈到模块化和组件化,现在我们来聊聊组件化开发背后的哪些事.最早是在广告SDK中应用组件化,但是同样适用于普通应用开发 以下高能,请做好心理准备,看不懂请发私信来交流 ...
- [Android Pro] 由模块化到组件化(一)
cp from : https://blog.csdn.net/dd864140130/article/details/53645290 在Android SDK一文中,我们谈到模块化和组件化,现在我 ...
- Android应用程序的基本组件介绍
1.Activity和View Activity是Android应用中负责与用户交互的组件,它只能通过setContentView(View)来显示指定组件. View组件是所有UI控件.容器空间的基 ...
- Android 开发:由模块化到组件化
在Android SDK一文中,我们谈到模块化和组件化,现在我们来聊聊组件化开发背后的哪些事.最早是在广告SDK中应用组件化,但是同样适用于普通应用开发 以下高能,请做好心理准备,看不懂请发私信来交流 ...
- Android零基础入门第2节:Android 系统架构和应用组件那些事
原文:Android零基础入门第2节:Android 系统架构和应用组件那些事 继上一期浅谈了Android的前世今生,这一期一起来大致回顾一下Android 系统架构和应用组件. 一.Android ...
- android笔记:获取View组件宽度以及ViewTreeObserver
View宽高测量方法: 测量方法有三种,如下: 1)(直接在onCreate()执行) int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureS ...
- 解决Android界面布局添加EditText组件后界面无法预览
错误报告: Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V Exception details are ...
随机推荐
- JavaScript基础知识----六道有趣的Js基础题以及解答
题目: 1.找出数字数组中最大的元素(使用Math.max函数)2.转化一个数字数组为function数组(每个function都弹出相应的数字)3.给object数组进行排序(排序条件是每个元素对象 ...
- iOS显示PDF
使用UIWebView来显示 //locale file NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUT ...
- 直播服务器Nginx
Mac直播服务器Nginx配置对HLS的支持 在上一篇中Mac上搭建直播服务器Nginx+rtmp,我们已经搭建了nginx+rtmp直播服务器.下面需要对Nginx服务器增加对HLS的支持.在Ngi ...
- android 获取本机号码需要root吗?
首先要明白,有的手机是获取不到自身的手机号的, 查了些资料,有以下两种方式可以获取到: 1. 通过对方给你发短信,打电话获取本机号码: 2. 还有一个就是通过APN来查询,但是这 ...
- 关于String和StringBuffer的理解问题:指针、变量的声明、变量的值的变化
问题描述: 首先,看一个小的测试程序: public static void main(String[] args) { testStringBuffer test = new testStringB ...
- java学习之线程池的实现
package com.gh.threadpoor; import java.util.concurrent.ExecutorService; import java.util.concurrent. ...
- Asteroids(最小点覆盖)
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18183 Accepted: 9905 Descri ...
- Pahom on Water(最大流)
Pahom on Water Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Python 第十二篇:HTML基础
一:基础知识: HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可 ...
- python中enumerate 函数
enumerate 函数用于遍历序列中的元素以及它们的下标: >>> for i,j in enumerate(('a','b','c')): print i,j 0 a 1 b ...