快速掌握Android三个常用自定义控件Toast AlertDialog Notification
2015-06-12 15:59
155 查看
网上相关自定义方法很多,总结整理了下安卓自定义Toast AlertDialog Notification:
Toast toast;
AlertDialog
Notification
//注意:RemoteViews不支持SeekBar
只支持类标识了@RemoteView的控件
/article/9076676.html
Toast toast;
public void myToast(Context context,String text){ if(toast==null){ toast=Toast.makeText(context, text, Toast.LENGTH_SHORT);//或自定义Toast toast=new Toast(this);toast.setView(view); toast.show(); }else{ toast.setText(text); toast.show(); } }
AlertDialog
public void myAlertDialog (){ View view=getLayoutInflater().inflate(R.layout.dialog,null);//dialog自定义布局 AlertDialog.Builder builder =new AlertDialog.Builder(this); AlertDialog show = builder.show(); show.getWindow().setContentView(view);//设置大小show.getWindow.setLayout(200,200); show.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); }
Notification
public void myNotification () { NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.custom); PendingIntent intent = PendingIntent.getActivity(context, 0, intent2, 0); Notification notification = new Notification(); notification.icon =R.drawable.ic_launcher;//图标 notification.tickerText = "通知";//标题 notification.contentView = views;//通知自定义布局 notification.flags=Notification.FLAG_NO_CLEAR;//点击不消失; notification.contentIntent = intent;//点击意图不能null nm.notify(1, notification); }
//注意:RemoteViews不支持SeekBar
只支持类标识了@RemoteView的控件
/article/9076676.html
相关文章推荐
- 浅谈JAVA反射机制在Android应用开发中的应用
- Android设计模式(十二)--抽象工厂模式
- android avd sdk root
- Android 使用SQLite
- Android自动化测试之MonkeyRunner
- Android_ContentProvider详解
- Android打包之bat脚本打包
- Android存储访问及目录
- android 生成 Bitmap 的常用几种方式
- Android - View绘图原理总结
- Android SimpleAdapter
- Android中XML文件的三种解析方式
- Android调用本地WebService
- [Android算法] Android蓝牙开发浅谈
- Android: 屏幕截图
- Android的进程回收机制
- 基于 vlc android截图录制视频等功能
- android获取手机Imei码
- 海思android4.4 SDK编译Latin输入法
- Android Studio新手完全指引