有没有办法确定Android应用是否全屏运行?

use*_*605 17 android

我只是想知道是否有一种简单的方法来查看在Android上运行的应用程序当前是否全屏显示.有没有办法查询android,看看你目前是在全屏模式或类似的东西?

VeV*_*VeV 13

刚刚完成Sigwann的回答:

boolean fullScreen = (getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
boolean forceNotFullScreen = (getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN) != 0;
boolean actionbarVisible = getActionBar().isShowing();
Run Code Online (Sandbox Code Playgroud)

  • 值得注意的是最后一行使用getActionBar().isShowing() - 如果你在主题中禁用了操作栏而不是隐藏它,那么getActionBar()可以返回null. (4认同)

小智 11

我想Commonsware想说getWindow().getAttributes()而不是getWindow().getFlags(); 因为据我所知,getFlags不存在.至少它不是在doc.

你需要读取getWindow().getAttributes().flags,这是一个int.

WindowManager.LayoutParams lp = getWindow().getAttributes();
int i = lp.flags;

根据android文档,FLAG_FULLSCREEN = 1024.所以你的旗帜是lp.flags的第11口

如果此咬合= 1,则激活全屏.


Ale*_*ecs 9

按照Sigwann的信息,这里是我的代码....

public boolean isFullScreen() {
    int flg = getWindow().getAttributes().flags;
    boolean flag = false;       
    if ((flg & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) {
        flag = true;
    }
    return flag;
}
Run Code Online (Sandbox Code Playgroud)

简单,但有效!


Com*_*are 7

你可以弄清楚你Activity是否正在通过全屏运行getWindow().getFlags().

但是,如果通过"申请"指的是其他人的申请,那么答案就是否定.