标签:flat drawable wrap string raw type [] 匹配 窗体
private final WindowManager.LayoutParams mParams = new WindowManager.LayoutParams(); public void showToast(String incomingNumber) { 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_NOT_TOUCHABLE 默认能够被触摸 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; params.format = PixelFormat.TRANSLUCENT; //在响铃的时候显示吐司,和电话类型一致 params.type = WindowManager.LayoutParams.TYPE_PHONE; params.setTitle("Toast"); //指定吐司的所在位置(将吐司指定在左上角) params.gravity = Gravity.LEFT+Gravity.TOP; //吐司显示效果(吐司布局文件),xml-->view(吐司),将吐司挂在到windowManager窗体上 mViewToast = View.inflate(this, R.layout.toast_view, null); tv_toast = (TextView) mViewToast.findViewById(R.id.tv_toast); //从sp中获取色值文字的索引,匹配图片,用作展示 mDrawableIds = 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}; int toastStyleIndex = SpUtil.getInt(getApplicationContext(), ConstantValue.TOAST_STYLE, 0); tv_toast.setBackgroundResource(mDrawableIds[toastStyleIndex]); //在窗体上挂在一个view(权限) mWM.addView(mViewToast, params); } <!-- 在窗体上挂在view的权限 --> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
标签:flat drawable wrap string raw type [] 匹配 窗体
原文地址:http://www.cnblogs.com/xufengyuan/p/6350301.html