是有没有人知道如何getWindow()服务在Android? [英] are there anybody know how to getWindow() in service on android?

查看:414
本文介绍了是有没有人知道如何getWindow()服务在Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过窗口管理器,在不活动视图。

I made a View without Activity by using WindowManager.

但我不得不改变视图状态像下面

but I have to change state of 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);

但getWindow()的服务将无法使用。

but getWindow() can not use in service.

有什么办法?

推荐答案

不可以得到一个服务的窗口。但是,您可以使用 窗口管理 添加为你已经做了一个视图(根)。

You can't get a window in a Service. But you can use WindowManager to add a view(root) as you did already.

和您还可以更新视图通过<一个href="http://developer.android.com/reference/android/view/ViewManager.html#updateViewLayout%28android.view.View,%20android.view.ViewGroup.LayoutParams%29"相对=nofollow> updateViewLayout ,你可以改变你的窗口的状态(窗式,旗,X,Y,W,H,重力等)中包含codeS。

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);

这篇关于是有没有人知道如何getWindow()服务在Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆