如何从服务中获取窗口? [英] How to get window from a Service?
本文介绍了如何从服务中获取窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 WindowManager
制作了一个没有 Activity
的 View
.
I made a View
without an Activity
by using the WindowManager
.
我想改变视图的状态,如下所示:
I want to change the state of the view like below:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
但我不能在 Service
中使用 getWindow()
.
but I cannot use getWindow()
in a Service
.
有没有办法做到这一点?
Is there a way to do this?
推荐答案
您不能在服务中获得窗口.但是您可以使用WindowManager像您一样添加一个视图(根).
You can't get a window in a Service. But you can use WindowManager to add a view(root) as you did already.
并且您还可以通过 updateViewLayout,您可以像下面的代码一样更改窗口的状态(窗口类型、标志、x、y、w、h、重力等...).
And You can also update view through updateViewLayout, you can change your window's status(window type, flag, x, y, w, h, gravity, etc...) like below codes.
private WindowManager mWindowManager;
private WindowManager.LayoutParams mLayoutParams;
..........
//let's assume that an event occurred
if(mConfiguration.orientation==Configuration.ORIENTATION_LANDSCAPE){
mLayoutParams.screenOrientation=Configuration.ORIENTATION_PORTRAIT;
}
mLayoutParams.softInputMode=WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
mLayoutParams.gravity = Gravity.TOP|Gravity.CENTER;
int flag=0
|WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
|WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
;
mLayoutParams.flags=flag;
mWindowManager.updateViewLayout(mRootView, mLayoutParams);
这篇关于如何从服务中获取窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文