在 Android 中以编程方式使应用程序全屏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10803973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:01:37  来源:igfitidea点击:

Programmatically make app FULL SCREEN in Android

androidandroid-layoutandroid-activity

提问by Wesley

I know that an app can be made full screen by tag in the manifest of the activity android:theme="@android:style/Theme.NoTitleBar.Fullscreen"Is it possible to switch to full screen mode from within the app, programmatically?

我知道可以通过活动清单中的标签使应用程序全屏显示android:theme="@android:style/Theme.NoTitleBar.Fullscreen"是否可以以编程方式从应用程序内切换到全屏模式?

回答by Samir Mangroliya

add two lines...

添加两行...

requestWindowFeature(Window.FEATURE_NO_TITLE); 
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);

回答by krystian71115

You can create new style and add

您可以创建新样式并添加

<item name="android:windowFullscreen">true</item>

<item name="android:windowFullscreen">true</item>

Or you can do it programmatically:

或者您可以以编程方式执行此操作:

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

回答by ρяσ?ρ?я K

add this in Activity onCreate before setContentView:

在 setContentView 之前在 Activity onCreate 中添加:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // remove title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
}

and in AndroidManifest.xml file:

并在 AndroidManifest.xml 文件中:

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>

回答by Nandha Krishnan

Try this,

尝试这个,

// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
                     setContentView(R.layout.main);

or

或者

<activity android:name=".ActivityName"
 android:label="@string/app_name"
 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

回答by dileep krishnan

in onCreate() method write

在 onCreate() 方法中写入

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

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