我有一个要求,比如我的应用程序没有在前台运行时需要显示一些图标。为此,我需要将视图添加到窗口管理器。是否可以在android tv中向窗口管理器添加视图。
这是我试过的代码
LayoutInflater inflater = LayoutInflater.from(getActivity());
final View layout = inflater.inflate(R.layout.layout_show_on_top_of_view, null);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.gravity = Gravity.TOP | Gravity.LEFT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.type = WindowManager.LayoutParams.TYPE_TOAST;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
params.format = PixelFormat.TRANSLUCENT;
params.windowAnimations = 0;
final WindowManager mWindowManager = (WindowManager)
getActivity().getSystemService(Context.WINDOW_SERVICE);
mWindowManager.addView(layout, params);
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mWindowManager.removeView(layout);
}
});
我尝试了不同的类型,但它不起作用。
答案 0 :(得分:1)
我认为您想要实现的目标可以通过透明的活动完成,请查看其他问题/答案:Is it possible to draw overlay over any screen using 3rd party app in android TV?