type :
WindowManager.LayoutParams.TYPE_TOAST
flag:
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
代码:
if (mVolumeView == null) {
WindowManager mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
View rootView = View.inflate(context, R.layout.volume_layout, null);
mVolumeView = (VolumeView) rootView.findViewById(R.id.volume);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_TOAST,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT);
layoutParams.gravity = Gravity.TOP;
mWindowManager.addView(rootView, layoutParams);
}

本文介绍了一个使用WindowManager显示Toast视图的方法。通过设置LayoutParams参数,包括类型为TYPE_TOAST、标志位FLAG_NOT_FOCUSABLE和FLAG_NOT_TOUCHABLE,使得视图不获取焦点且不可触摸。此外,还展示了如何通过LayoutInflater加载布局并添加到WindowManager中。
4136

被折叠的 条评论
为什么被折叠?



