-
OptionMenu查看全部
-
1.NotificationManager manager;//通知控制类 2.manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);//初始化 3.定義 notification_ID; 4.manager.notify(notification_ID, notification); 5.manager.cancel(notification_ID);//取消notification查看全部
-
//以下設定均需要權限 // builder.setDefaults(Notification.DEFAULT_SOUND);//设置提示声音 // builder.setDefaults(Notification.DEFAULT_LIGHTS);//设置指示灯 // builder.setDefaults(Notification.DEFAULT_VIBRATE);//设置震动 builder.setDefaults(Notification.DEFAULT_ALL);//设置以上所有的效果 Notification notification = builder.build();//4.1以上 //builder.getNotification();//4.1以下用來獲取notification的方法 manager.notify(notification_ID, notification); }查看全部
-
一、實現 OnClickListener接口public class MainActivity extends Activity implements OnClickListener{ 二、构造notification并发送到通知栏 /** * 构造notification并发送到通知栏*/ private void sendNotification(){ Intent intent = new Intent(this,MainActivity.class); PendingIntent pintent = PendingIntent.getActivity(this, 0, intent, 0); Builder builder = new Notification.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher);//设置图标 builder.setTicker("hello");//手机状态栏的提示; builder.setWhen(System.currentTimeMillis());//设置时间 builder.setContentTitle("通知栏通知");//设置标题 builder.setContentText("我来自NotificationDemo");//设置通知内容 builder.setContentIntent(pintent);//点击后的意图查看全部
-
如何實現通知欄查看全部
-
通知欄內容查看全部
-
/** * 显示自定义对话框 */ private void showDialog5() { LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.dialog_layout, null); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("自定义对话框");//设置标题 builder.setIcon(R.drawable.ic_launcher);//设置图标 builder.setView(view); AlertDialog dialog = builder.create();//获取dialog dialog.show();//显示对话框 } }查看全部
-
/** * 显示列表对话框 */ private void showDialog4() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("部门列表");//设置标题 builder.setIcon(R.drawable.ic_launcher);//设置图标 builder.setItems(item_list, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(MainActivity.this, "我动了"+item_list[which]+"!", Toast.LENGTH_SHORT).show(); } }); AlertDialog dialog = builder.create();//获取dialog dialog.show();//显示对话框 }查看全部
-
/** * 显示多选按钮对话框 */ private void showDialog3() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("爱好");//设置标题 builder.setIcon(R.drawable.ic_launcher);//设置图标 builder.setMultiChoiceItems(multi_list, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { // TODO Auto-generated method stub if(isChecked){ Toast.makeText(MainActivity.this, "我喜欢上了"+multi_list[which]+"!", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(MainActivity.this, "我不喜欢"+multi_list[which]+"了!", Toast.LENGTH_SHORT).show(); } } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss(); } }); AlertDialog dialog = builder.create();//获取dialog dialog.show();//显示对话框 }查看全部
-
/** * 显示单选按钮对话框 */ private void showDialog2() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("选择性别");//设置标题 builder.setIcon(R.drawable.ic_launcher);//设置图标 builder.setSingleChoiceItems(single_list, 0,//0表示默認第一個option被選中 new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub String str = single_list[which]; Toast.makeText(MainActivity.this, "这个人是"+str+"!", Toast.LENGTH_SHORT).show(); } }); AlertDialog dialog = builder.create();//获取dialog dialog.show();//显示对话框 }查看全部
-
/** * 显示确认对话框 */ private void showDialog1() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("确认对话框");//设置标题 builder.setIcon(R.drawable.ic_launcher);//设置图标 builder.setMessage("确认对话框提示内容");//设置内容 builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {//這個OnClicklistener和上面的包不一樣 @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "点击了确定按钮!", Toast.LENGTH_SHORT).show(); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "点击了取消按钮!", Toast.LENGTH_SHORT).show(); } }); AlertDialog dialog = builder.create();//获取dialog dialog.show();//显示对话框 }查看全部
-
大致介紹查看全部
-
/** * 完全自定义的Toast */ private void showToast4(){ LayoutInflater inflater = LayoutInflater.from(this); View toast_view = inflater.inflate(R.layout.toast_layout, null); Toast toast = new Toast(this); toast.setView(toast_view); toast.show(); }查看全部
-
/** * 带有图片的toast; */ private void showToast3(){ Toast toast = Toast.makeText(this,"带有图片的Toast!",Toast.LENGTH_LONG); LinearLayout toast_layout = (LinearLayout)toast.getView(); ImageView iv = new ImageView(this); iv.setImageResource(R.drawable.topimg); toast_layout.addView(iv,0); toast.show(); }查看全部
-
/** * 显示自定义位置的Toast */ private void showToast2(){ Toast toast = Toast.makeText(this,"改变位置的Toast!",Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }查看全部
举报
0/150
提交
取消