自定义Toast,兼容那些安装时把通知关掉还问为啥不给提示的测试人员
2017-08-22 10:48
381 查看
public class MyToast{ long mDurationMillis; private Context mContext; Dialog builder; Handler ha=new Handler(); View view; public static MyToast makeText(Context context, String text, long duration) { return new MyToast(context,text,duration); } public MyToast(Context context,String text,long duration) { view = Toast.makeText(context.getApplicationContext(), text, Toast.LENGTH_SHORT).getView(); if (view != null) { TextView tv = (TextView) view.findViewById(android.R.id.message); tv.setText(text); } setDuration(duration); builder=new Dialog(context,R.style.Toast); //先得到构造器 ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ); builder.addContentView(view,params); Window window = builder.getWindow(); // 可以在此设置显示动画 WindowManager.LayoutParams wl = window.getAttributes(); wl.y = ((Activity)context).getWindowManager().getDefaultDisplay().getHeight()/5; // 以下这两句是为了保证按钮可以水平满屏 wl.width = ViewGroup.LayoutParams.WRAP_CONTENT; wl.height = ViewGroup.LayoutParams.WRAP_CONTENT; // 设置显示位置 builder.onWindowAttributesChanged(wl); } /** * Set the location at which the notification should appear on the screen. * */ public MyToast setDuration(long durationMillis) { if (durationMillis < 0) { mDurationMillis = 0; } if (durationMillis == Toast.LENGTH_SHORT) { mDurationMillis = 2000; } else if (durationMillis == Toast.LENGTH_LONG) { mDurationMillis = 3500; } else { mDurationMillis = durationMillis; } return this; } public void show() { builder.show(); ha.postDelayed(new Runnable() { @Override public void run() { if(builder.isShowing()) { try { builder.cancel(); }catch (IllegalArgumentException e){ } } } }, mDurationMillis); } public void setText(String text) { TextView tv = (TextView) view.findViewById(android.R.id.message); tv.setText(text); } }
相关文章推荐
- 通知栏自定义安装提示
- win10上 安装Sqlserver2008R2数据库提示.NET Framework3.5不存在,解决之后仍然提示兼容问题安装不成功
- android 测试更新app时 提示“未安装应用程序”
- centos6.0 安装ie6 (兼容测试用的到)
- 安装后启动虚拟机,提示虚拟机版本不兼容,无法使用的解决办法
- 简单自定义Toast,实现好看的消息提示框
- iOS 自动化打包发布测试平台后邮件通知测试人员(在Mac使用Python脚本发送邮件)
- 论坛源码推荐(2月17日):FLKAutoLayout-简单创建布局约束 CRToast--自定义通知
- 杀死进程、退出应用程序时提示、自定义apk安装、反编译
- Windows2003 + IIS6 安装.Net FrameWork 4.0 兼容早期版本的测试
- android 测试更新app时 提示“未安装应用程序”
- [Asp.net4.0]Windows2003 + IIS6 安装.Net FrameWork 4.0 兼容早期版本的测试
- Windows2003 + IIS6 安装.Net FrameWork 4.0 兼容早期版本的测试
- [控件]NotificationManager提示通知(三)自定义通知
- Android开发必知--自定义Toast提示
- Android自定义Toast弹出消息提示
- 提示控件之自定义Toast
- 添加X-UA-Compatible标签,提示用户安装GFC, 兼容 IE浏览器
- Windows2003 + IIS6 安装.Net FrameWork 4.0 兼容早期版本的测试
- 安卓通知栏自定义布局提示(NotificationCompat.Builder)