自定义toast

来源:互联网 发布:老徐外设店淘宝 编辑:程序博客网 时间:2024/04/27 14:54


看源码

public void showToast(String incomingNumber) {// TODO Auto-generated method stub// Toast.makeText(getApplicationContext(), incomingNumber, 0).show();final WindowManager.LayoutParams params = mParams;params.height = WindowManager.LayoutParams.WRAP_CONTENT;params.width = WindowManager.LayoutParams.WRAP_CONTENT;params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;params.format = PixelFormat.TRANSLUCENT;params.type = WindowManager.LayoutParams.TYPE_TOAST;params.setTitle("Toast");params.gravity = Gravity.LEFT + Gravity.TOP;viewToast = View.inflate(getApplicationContext(),R.layout.toast_phone_view, null);tv_phone_toast = (TextView) viewToast.findViewById(R.id.tv_phone_toast);int phone_toast_style = SpUtil.getInt(getApplicationContext(),ConstantValue.PHONE_TOAST_STYLE, 0);int[] toastStyleIndex = new int[] { R.drawable.call_locate_white,R.drawable.call_locate_orange, R.drawable.call_locate_blue,R.drawable.call_locate_gray, R.drawable.call_locate_green };tv_phone_toast.setBackgroundResource(toastStyleIndex[phone_toast_style]);query(incomingNumber);mWM.addView(viewToast, params);}


原创粉丝点击