前十天去了北京,今天又开始学习Android 了。
1、popUpWindow基本使用。
1)先获取作为popUpWindow布局的View对象。
2)生成一个popUpWindow对象,并进行一些设置。
3)调用showAtLocation或者是showAsDropDown函数显示popUpWindow
View v = this.getLayoutInflater().inflate(R.layout.layout4popupwindow, null);//获取作为popUpWindow背景的View对象。
about = new PopupWindow(v, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);//生成一个popUpWindow对象
findViewById(R.id.press).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(about.isShowing()){
about.dismiss();
}else{
about.setOutsideTouchable(true);
about.setFocusable(false);
about.setTouchable(true);
//about.showAtLocation(findViewById(R.id.e), Gravity.LEFT, 50, 0);
about.showAsDropDown(v);
}
}
});
之后如果想要对popUpWindow中的空间进行监听,可以使用v.findViewById方法。
v.findViewById(R.id.buuton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(_tempTest_popUpWindowActivity.this, "aaaaaaaa", 1).show();
// TODO Auto-generated method stub
}
});
2、Notification的基本用法。
1)首先要生成一个Notification对象。
2)对Notification对象各向参数进行设置。
3)用getSystemService函数生成一个NotificationManager对象,再将Notification对象添加进去。
Intent intent = new Intent();
PendingIntent pi = PendingIntent.getActivity(_tempTest_NotificationActivity.this, 0, intent, 0);//即使不想点击Notification跳出一个Activity,也必须添加此对象,否则Notification不能正常显示。
Notification note = new Notification(R.drawable.ic_launcher, "start a notification",System.currentTimeMillis());
note.defaults = Notification.DEFAULT_LIGHTS;
note.defaults = Notification.DEFAULT_SOUND;
note.vibrate = new long[]{10,100,100,100};//以上设置都是必要的
note.setLatestEventInfo(_tempTest_NotificationActivity.this, "NEWS TODAYS", "NOTHING NEW", pi);//设置显示的标题和内容
NotificationManager noti = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
noti.notify(a, note);//a是一个int型,表示该Notification的ID
最后,记得要在AndroidManifest文件中添加闪光灯和振动器的权限。
<uses-permission android:name="android.permission.FLASHLIGHT"/> <uses-permission android:name="android.permission.VIBRATE"/>
可是使用NotificationManager.cancel方法取消某ID的通知。