Android全屏代码无效

时间:2015-06-17 13:37:59

标签: java android eclipse

我正在使用这些线来全屏,但电池和天线的栏仍然存在。

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(
        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

我甚至检查了How to get rid of top fading edge in android full screen mode?中提到的一行 当我添加(setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);)时,屏幕会上升,但有点像条形图在屏幕上方。 我自然地认为操作系统(Android 4.0.4)不允许这样做,但据说这段代码会强制它像那样,但它不起作用,最后的代码更精确的是:

public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
        getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        setListAdapter(new ArrayAdapter<String>(Menu.this,
                android.R.layout.simple_list_item_1, classes));
    }

请你帮我吗?

5 个答案:

答案 0 :(得分:2)

你正在做的每一件事情都是代码很简单,以获得全屏

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //if you want it too other vice first one is good enough
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

**

  

请注意,请在setContentView

之前添加

**

答案 1 :(得分:1)

编辑:看起来你已经把一切都搞定了,除了你有两次标志FLAG_FORCE_NOT_FULLSCREEN

首先,确保您的主题不包含操作栏。然后,在onCreate中添加以下内容:

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

答案 2 :(得分:1)

要在全屏使用中显示应用:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

要删除它,请使用:

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

答案 3 :(得分:1)

全屏活动您必须在super.onCreate(savedInstanceState);

之前使用以下代码
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

或者如果您在应用程序中使用Theme.AppCompat,可以在style.xml中添加以下样式来使用FullScreenTheme

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" 
 parent="@style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
  

并在您的清单文件中提及

    <activity
      android:name=".activities.FullViewActivity"
      android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen" 
     />

答案 4 :(得分:0)

这就是你要找的东西:

https://developer.android.com/training/system-ui/immersive.html

另外,我附上一个相关的问题:

Using new IMMERSIVE mode in android kitkat