如何在设置活动android中更改全屏模式?

时间:2014-10-15 13:20:37

标签: android settings fullscreen

我想在设置中更改全屏模式,并在从设置备份到主活动后查看更改。 我试过了:

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

但是在设置主要活动的内容视图后我无法使用它。我也试过了:

WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
mActivity.getWindow().setAttributes(attrs);

但我不能在onResume()中使用它,因为我的应用程序无法恢复在第一次打开时抛出空指针异常的活动。 您是否知道在恢复主要活动后如何进行全屏设置并看到更改?

4 个答案:

答案 0 :(得分:1)

Api等级11 +

getActionBar.hide();

低于Api等级11

you can use getSupportActionBar.hide();并将v7支持lib添加到您的项目中

答案 1 :(得分:0)

如果您使用的是最近的Android(4.4),可以尝试将其添加到onResume()

    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
         | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
         | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
         | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
         | View.SYSTEM_UI_FLAG_FULLSCREEN
         | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

答案 2 :(得分:0)

在AndroidManifest.xml中

        <activity
            android:name=".YourSettingsActivity"
            android:label=""
            android:theme="@android:style/Theme.Holo.NoActionBar.FullScreen"
            android:screenOrientation="portrait" >
        </activity>

答案 3 :(得分:0)

试试这个

WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);