自定义Dialog:
一.使用DialogActivity将一个activity变成Dailog样式显示。
Dialog有很多类型(单选,多选,进度条,简单显示文本,自定义等)
public class DialogActivity extends Activity { private final static int SIMPLE_DIALOG= 1; private final static int CUSTOM_VIEW_DIALOG=2; private final static int PROGRESS_DIALOG=3; Dialog d; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.dialog); findViewById(R.id.button1).setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) { DialogActivity.this.showDialog(SIMPLE_DIALOG, null); } }); findViewById(R.id.button2).setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) { DialogActivity.this.showDialog(CUSTOM_VIEW_DIALOG, null); } }); findViewById(R.id.button3).setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) { DialogActivity.this.showDialog(PROGRESS_DIALOG, null); } }); @Override protected Dialog onCreateDialog(int id, Bundle args) { //简单的Dialog ,显示标题,内容,图标 if(SIMPLE_DIALOG==id) return new AlertDialog.Builder(this) .setTitle("tille") .setIcon(android.R.drawable.ic_dialog_alert) .setMessage("thisis message") .create(); //自定义布局的Dialog else if(CUSTOM_VIEW_DIALOG == id){ LayoutInflater inflater=LayoutInflater.from(this); return new AlertDialog.Builder(this) .setView(inflater.inflate( R.layout.dialog, null) ) .setTitle("tille") .setIcon(android.R.drawable.ic_dialog_alert) .setMessage("thisis message") .setPositiveButton("OK", null) .setNegativeButton("Cancle", null) .create(); } //进度条类型Dialog else if(PROGRESS_DIALOG==id){ ProgressDialog dialog=new ProgressDialog(this); dialog.setTitle("title"); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); //进度条类型(长条型,圆圈型等) dialog.setMax(100); dialog.incrementProgressBy(20); //自定了当前进度(一般要通过具体业务实现) return dialog; } return super.onCreateDialog(id); } }
二.创建一个Dialog再进行调用
在values文件夹下的styles文件中配置
<style name="MyDialog" parent="@android:Theme.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> //设置Dialog无标题 <item name="android:windowBackground">@color/blue</item> //设置背景 <item name="android:windowIsFloating">true</item> //设置Dialog悬浮 <item name="android:windowContentOverlay">@null</item> </style>
创建自定义Dialog类
public class FriendsMsgDialog extends Dialog {
Context context;
int position;
MyApplication application;
ImageView icon;
TextView nickname;
TextView address;
TextView sex;
TextView phone;
JSONArray array;
LayoutInflater inflater;
//重载构造函数
public FriendsMsgDialog(Context context, int theme,int position,JSONArray array) {
super(context, theme);
this.context=context;
this.position=position;
this.array=array;
application=(MyApplication) context.getApplicationContext();
inflater=LayoutInflater.from(context);
}
//要实现onCreate(Bundle savedInstanceState) 方法
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); View view=inflater.inflate(R.layout.friends_msg,null); JSONObject obj; try { obj = (JSONObject) array.get(position); //获取自定义Dialog界面上的各个组件 icon=(ImageView) view.findViewById(R.id.img_dtlfriends_icon); nickname=(TextView) view.findViewById(R.id.tv_dtlfriends_nickname); address=(TextView) view.findViewById(R.id.tv_dtlfriends_address); sex=(TextView) view.findViewById(R.id.tv_dtlfriends_sex); phone=(TextView) view.findViewById(R.id.tv_dtlfriends_phone); //给各组件赋值(通过具体业务) nickname.setText(obj.getString("nick_name")); address.setText(obj.getString("address")); sex.setText(obj.getString("sex")); phone.setText(obj.getString("phone")); GetIcon.getview(obj.getString("icon"), icon); } catch (JSONException e) { e.printStackTrace(); } setContentView(view); } }
调用Diaog
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { //长按listView的某一项显示Dialog if(dialog==null){ dialog=new FriendsMsgDialog(context, R.style.MyDialog,position,array); dialog.show(); }else dialog.show(); return true;
系统消息通知:
NotificationManager nm; findViewById(R.id.button6).setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View arg0) { installNotificaiton(); } }); private void installNotificaiton() { //获取系统 通知服务 nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); //创建一个通知 Notification nf=new Notification(); //设置状态text nf.tickerText="new messages incoming..."; //设置时间 nf.when=System.currentTimeMillis(); //设置icon nf.icon=R.drawable.ic_launcher; //设置特性 nf.flags=nf.FLAG_AUTO_CANCEL ; //点击消息跳转到MainActivity PendingIntent pi=PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class ),PendingIntent.FLAG_CANCEL_CURRENT); nf.setLatestEventInfo(this, "title", "somebody send you msg", pi); nm.notify(2014, nf); }
相关推荐
仿京东快报效果,自定义控件,每隔3秒轮播一条通知消息~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Notification系统通知和自定义通知小列子
NULL 博文链接:https://android-zhang.iteye.com/blog/1488932
轻量万能自定义信息管理系统软件是为了解决所有企业团队或个体商户所面临的业务管理难,市场上找不到一款适合自己需要的,同时操作起来与Execl表格又相差不大的信息管理软件。具资料查询管理、小微计算、统计汇总,...
写的一个android通知,有网上找来的一段系统的通知代码,自己写了一个自定义的通知的方法。
详细的自定义工作流系统的设计与实现文档 包括工作流引擎的设计方案 可视化操作的实现。并附有技术难点的提示
您可以用API函数SetWindowLong指定处理消息的窗口过程(window procedure)为自定义的函数WindowProc,捕获消息ID为WM_USER+1的自定义消息或系统消息。并且,为了保证窗口能正确的响应消息,需要保存原来默认的窗口...
可自定义制作生成绝大多数逻辑问卷调查 可自定义制作生成绝大多数网络考试系统,自动打分 可自定义制作生成绝大多数产品反馈系统 可自由编辑界面,所有用户界面均采用纯Html页面(模版生成) 随时可对使用中投票调查...
用户自定义日程安排系统后台框架。
1.包含自定义消息 2.包含Panel类型的自定义插件 3.包含Display类型的自定义插件
超强自定义问卷调查系统是少有的采用纯静态实现的问卷调查系统,其性能和可定义性从技术本身就决定了其优势。 超强自定义问卷调查系统由佰思科技(Bicesoft.com)独立开发,根据第三方统计记录,截至2011年11月...
根据给定的消息协议,自己定义一个消息类,编写好服务端与客户端,自定义好编解码器,在客户端发送此消息,服务端获取消息并向客户端发送同样格式的消息;导入Eclipse maven项目运行即可跑通。
用户自定义日程安排系统后台框架。
在MFC中自定义一种消息机制,原来的消息机制非常局限,必须窗口句柄,这种不需要窗口句柄即可传递消息
可以列举当前所有窗口,自定义并发送Windows消息。 要VC6.0运行库支持。
制作自定义CentOS系统,制作自定义CentOS系统,制作自定义CentOS系统,制作自定义CentOS系统,制作自定义CentOS系统
具体操作:自定义消息通知内容布局;点击界面中心的“点击发送消息”TextView控件,模拟发送通知消息,通知栏接收消息,点击几次则发送几次,点击通知栏消息,跳转到详情界面。 1.activity_main.xml: <...
Winform自定义消息框,好看的消息提示Alert源码,国外大神,很基础的实现,可以在此基础上进行优化和进一步调整。Winform控件、Winform优美提示框、消息框、Alert信息弹窗、Notification
自定义消息 MFC 入门 自定义消息 MFC 对话框
自定义消息,VC里面 自定义消息的实现,已经运行调式成功