If you don't want to use the theme @android:style/Theme.NoTitleBar.Fullscreen because you are already using a theme of you own, you can use android:windowFullscreen.
<activity
android:name=".Launch"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > <!-- This line is important -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Launch"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > <!-- This line is important -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
override fun onCreate(savedInstanceState: Bundle?) {
/* Put above code here ..... */
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_slider)
}
注意
我在 Pixel 3A 模拟器中检查了这段代码
也许自定义 android 操作系统不支持
设置样式
For AndroidX
1. Transparent Statusbar
window?.decorView?.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
window.statusBarColor = Color.TRANSPARENT
override fun onCreate(savedInstanceState: Bundle?) {
/* Put above code here ..... */
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_slider)
}
Note
I checked this code in Pixel 3A emulator
Maybe customise android OS not support
set style <style name="Theme.FullScreen" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
</style>
<style name="FullScreenTheme" parent="AppTheme">
<!--this property will help hide the ActionBar-->
<item name="windowNoTitle">true</item>
<!--currently, I don't know why we need this property since use windowNoTitle only already help hide actionbar. I use it because it is used inside Theme.AppCompat.Light.NoActionBar (you can check Theme.AppCompat.Light.NoActionBar code). I think there are some missing case that I don't know-->
<item name="windowActionBar">false</item>
<!--this property is used for hiding StatusBar-->
<item name="android:windowFullscreen">true</item>
</style>
隐藏系统导航栏
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
setContentView(R.layout.activity_main)
...
}
}
二.您的主要应用主题是Theme.AppCompat.Light.NoActionBar
用于隐藏 ActionBar / StatusBar style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
</style>
<style name="FullScreenTheme" parent="AppTheme">
<!--don't need any config for hide ActionBar because our apptheme is NoActionBar-->
<!--this property is use for hide StatusBar-->
<item name="android:windowFullscreen">true</item> //
</style>
I. Your main app the theme is Theme.AppCompat.Light.DarkActionBar
For hide ActionBar / StatusBar style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
</style>
<style name="FullScreenTheme" parent="AppTheme">
<!--this property will help hide the ActionBar-->
<item name="windowNoTitle">true</item>
<!--currently, I don't know why we need this property since use windowNoTitle only already help hide actionbar. I use it because it is used inside Theme.AppCompat.Light.NoActionBar (you can check Theme.AppCompat.Light.NoActionBar code). I think there are some missing case that I don't know-->
<item name="windowActionBar">false</item>
<!--this property is used for hiding StatusBar-->
<item name="android:windowFullscreen">true</item>
</style>
To hide the system navigation bar
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
setContentView(R.layout.activity_main)
...
}
}
II. Your main app theme is Theme.AppCompat.Light.NoActionBar
For hide ActionBar / StatusBar style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
</style>
<style name="FullScreenTheme" parent="AppTheme">
<!--don't need any config for hide ActionBar because our apptheme is NoActionBar-->
<!--this property is use for hide StatusBar-->
<item name="android:windowFullscreen">true</item> //
</style>
I wanted to use my own theme instead of using @android:style/Theme.NoTitleBar.Fullscreen. But it wasn't working as some post on here had mentioned, so I did some tweaking to figure it out.
Note: in my case I had to use name="windowActionBar" instead of name="android:windowActionBar" before it worked properly. So I just used both to make sure in the case I need to port to a new Android version later.
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) hideSystemUI() }
private fun hideSystemUI() {
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN) }
// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
private fun showSystemUI() {
window.decorView.systemUiVisibility =
(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) }
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) hideSystemUI() }
private fun hideSystemUI() {
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN) }
// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
private fun showSystemUI() {
window.decorView.systemUiVisibility =
(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) }
// add following lines before setContentView
// to hide toolbar
if(getSupportActionBar()!=null)
getSupportActionBar().hide();
//to hide status bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
这将隐藏工具栏和状态栏。
但在某些情况下,您可能希望显示具有透明背景的状态栏,在这种情况下,请执行以下操作:
// add following lines before setContentView
// to hide toolbar
if(getSupportActionBar()!=null)
getSupportActionBar().hide();
// to make status bar transparent
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
fun AppCompatActivity.makeItFullScreenStatusBarVisible(){
supportActionBar?.hide()
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}
在 setContentView 之前调用:
makeItFullScreenStatusBarVisible()
对于第二种情况:
fun AppCompatActivity.makeItFullScreenStatusBarHidden(){
supportActionBar?.hide()
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
在 setContentView 之前调用:
makeItFullScreenStatusBarHidden()
To make your activity full screen do this:
// add following lines before setContentView
// to hide toolbar
if(getSupportActionBar()!=null)
getSupportActionBar().hide();
//to hide status bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
This will hide the toolbar and status bar.
But In some case, you may want to show status bar with a transparent background, in that case, do this:
// add following lines before setContentView
// to hide toolbar
if(getSupportActionBar()!=null)
getSupportActionBar().hide();
// to make status bar transparent
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
Some other alternate to hide toolbar instead of getSupportActionBar().hide():
Remove toolbar by changing the app theme's parent:
If you want to remove the toolbar from only one activity then go to manifest, under activity tag add this: android:theme="@style/Theme.AppCompat.Light.NoActionBar"
For kotlin lovers, why not use extension functions:
For first case:
fun AppCompatActivity.makeItFullScreenStatusBarVisible(){
supportActionBar?.hide()
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}
And call this before setContentView:
makeItFullScreenStatusBarVisible()
For Second One:
fun AppCompatActivity.makeItFullScreenStatusBarHidden(){
supportActionBar?.hide()
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.decorView.windowInsetsController?.hide(WindowInsets.Type.systemBars())
} else {
@Suppress("DEPRECATION") // Older API support
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
As of 2022
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.decorView.windowInsetsController?.hide(WindowInsets.Type.systemBars())
} else {
@Suppress("DEPRECATION") // Older API support
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
public static void setSize( final int width, final int height ){
//DO SOME OTHER STUFF...
instance_.getWindow().setLayout( width, height );
// Prevent status bar re-appearance
Handler delay = new Handler();
delay.postDelayed( new Runnable(){ public void run() {
instance_.getWindow().setLayout(
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.FILL_PARENT );
}}, FILL_PARENT_ON_RESIZE_DELAY_MILLIS );
}
然后窗口正确地重新调整大小,并且无论触发此事件的事件如何,状态栏都不会重新出现。
TIP: Using getWindow().setLayout() can screw up your full screen display! Note the documentation for this method says:
Set the width and height layout parameters of the window...
you can change them to ... an absolute value to make a window that is not full-screen.
For my purposes, I found that I had to use setLayout with absolute parameters to resize my full screen window correctly. Most of the time, this worked fine. It was called by an onConfigurationChanged() event. There was a hiccup, however. If the user exited the app, changed the orientation, and reentered, it would lead to firing off my code which included setLayout(). During this re-entry time window, my status bar (which was hidden by the manifest) would be made to re-appear, but at any other time setLayout() would not cause this! The solution was to add an additional setLayout() call after the one with the hard values like so:
public static void setSize( final int width, final int height ){
//DO SOME OTHER STUFF...
instance_.getWindow().setLayout( width, height );
// Prevent status bar re-appearance
Handler delay = new Handler();
delay.postDelayed( new Runnable(){ public void run() {
instance_.getWindow().setLayout(
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.FILL_PARENT );
}}, FILL_PARENT_ON_RESIZE_DELAY_MILLIS );
}
The window then correctly re-sized, and the status bar did not re-appear regardless of the event which triggered this.
class LoginActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_FULLSCREEN
}
}
Immersive Mode
The immersive mode is intended for apps in which the user will be heavily interacting with the screen. Examples are games, viewing images in a gallery, or reading paginated content, like a book or slides in a presentation. For this, just add this lines:
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
Sticky immersive
In the regular immersive mode, any time a user swipes from an edge, the system takes care of revealing the system bars—your app won't even be aware that the gesture occurred. So if the user might actually need to swipe from the edge of the screen as part of the primary app experience—such as when playing a game that requires lots of swiping or using a drawing app—you should instead enable the "sticky" immersive mode.
This code will work for notch screen also. To check the notch fullscreen you require android P but if You have a notch display phone then go to setting-->Display setting -->app display ratio --->select your app --->there will be two options safe are display and full screen , please select the full screen and run the app, you can see the fullscreen in notch also without having android Pie
发布评论
评论(30)
您可以通过编程方式执行此操作:
或者您可以通过
AndroidManifest.xml
文件执行此操作:编辑:
如果您使用的是 AppCompatActivity,则需要添加一个新主题:
然后使用它。
由于:
https://stackoverflow.com/a/25365193/1646479
You can do it programmatically :
Or you can do it via your
AndroidManifest.xml
file:Edit:
If you are using AppCompatActivity then you need to add a new theme:
and then use it.
Thanks to:
https://stackoverflow.com/a/25365193/1646479
KitKat 中提供了一种名为沉浸式全屏模式的技术。
示例
There's a technique called Immersive Full-Screen Mode available in KitKat.
Example
如果您不想使用主题
@android:style/Theme.NoTitleBar.Fullscreen
因为您已经在使用自己的主题,则可以使用android:windowFullscreen
>。在 AndroidManifest.xml 中:
在 styles.xml 中:
If you don't want to use the theme
@android:style/Theme.NoTitleBar.Fullscreen
because you are already using a theme of you own, you can useandroid:windowFullscreen
.In AndroidManifest.xml:
In styles.xml:
在 AndroidManifest.xml 文件中:
或在 Java 代码中:
In AndroidManifest.xml file:
Or in Java code:
对于 AndroidX
1. 透明状态栏
2. 透明状态栏和透明状态栏底部导航栏
3. 隐藏状态栏
API 30+ 推荐的兼容解决方案(包括向后兼容性)
https://developer.android.com/training/system-ui/immersive
4. 隐藏状态栏和状态栏底部导航栏
API 级别 30:
与3.相同,只需使用
WindowInsetsCompat.Type.systemBars()
https://developer.android.com/training/system-ui/immersive
< img src="https://i.sstatic.net/PcmLFl.png" alt="在此处输入图像描述">
将此代码放在哪里?
注意
For AndroidX
1. Transparent Statusbar
2. Transparent Statusbar & Bottomnav bar
3. Hide Statusbar
Recommended Compat solution for API 30+ (inclusive backwards compatibility)
https://developer.android.com/training/system-ui/immersive
4. Hide Statubar & Bottomnav bar
API level 30:
Same as 3., just use
WindowInsetsCompat.Type.systemBars()
https://developer.android.com/training/system-ui/immersive
Where to put this code ?
Note
<style name="Theme.FullScreen" parent="Theme.MaterialComponents.DayNight.NoActionBar">
如果您使用 AppCompat 和 ActionBarActivity,请使用此
getSupportActionBar().hide();
If your using AppCompat and ActionBarActivity, then use this
getSupportActionBar().hide();
请注意,
如果您使用任何方法设置操作栏,如下所示:
它将导致空指针异常。
Be careful with
If you are using any method to set the action bar as the follow:
It will cause a null pointer exception.
使用
style.xml
中的 appcompat 尝试此操作。它为所有平台提供支持。Try this with appcompat from
style.xml
. It provides support for all platforms.使用Android Studio(当前版本是2.2.2)可以非常轻松地添加全屏活动。
查看步骤:
完成!
现在您已经轻松制作了一个全屏活动(请参阅 java 类和活动布局以了解其工作原理)!
Using Android Studio (current version is 2.2.2 at moment) is very easy to add a fullscreen activity.
See the steps:
Done!
Now you have a fullscreen activity made easily (see the java class and the activity layout to know how the things works)!
首先,您必须使用“NoActionBar”设置应用程序主题,如下所示,
然后在全屏活动中添加这些行。
它将隐藏全屏活动中的操作栏/工具栏以及状态栏
First you must to set you app theme with "NoActionBar" like below
Then add these lines in your fullscreen activity.
It will hide actionbar/toolbar and also statusbar in your fullscreen activity
对于那些使用 AppCompact 的人...
style.xml
然后将名称放入清单中...
For those using AppCompact...
style.xml
Then put the name in your manifest...
AndroidManifest.xml
I. 您的主应用程序主题是Theme.AppCompat.Light.DarkActionBar
用于隐藏 ActionBar / StatusBar
style.xml
隐藏系统导航栏
二.您的主要应用主题是Theme.AppCompat.Light.NoActionBar
用于隐藏 ActionBar / StatusBar
style.xml
隐藏系统导航栏
类似如
Theme.AppCompat.Light.DarkActionBar
。演示
AndroidManifest.xml
I. Your main app the theme is Theme.AppCompat.Light.DarkActionBar
For hide ActionBar / StatusBar
style.xml
To hide the system navigation bar
II. Your main app theme is Theme.AppCompat.Light.NoActionBar
For hide ActionBar / StatusBar
style.xml
To hide the system navigation bar
Similar like
Theme.AppCompat.Light.DarkActionBar
.Demo
感谢您的回答@Cristian 我收到错误
我使用以下方法解决了这个问题
thanks for answer @Cristian i was getting error
i solved this using
在 styles.xml 中添加此
示例 -
并使用以下代码
示例更改 AndroidManifest 文件 -
Add this in styles.xml
Example -
And change AndroidManifest file with bellow code
Example -
主题
AndroidManifest
Theme
AndroidManifest
显示完全沉浸式:
退出完全沉浸式模式:
show Full Immersive:
move out of full immersive mode:
这是一个示例代码。您可以打开/关闭标志来隐藏/显示特定部分。
然后,您重置为默认状态:
您可以在
onCreate
中调用上述函数:Here is an example code. You can turn on/off flags to hide/show specific parts.
Then, you reset to the default state:
You can call the above functions from your
onCreate
:就称这很有趣:
just call this fun :
我想使用我自己的主题而不是使用@android:style/Theme.NoTitleBar.Fullscreen。但它并不像这里的一些帖子提到的那样工作,所以我做了一些调整来解决这个问题。
在 AndroidManifest.xml 中:
在 styles.xml 中:
注意:在我的例子中,我必须使用
name="windowActionBar"
而不是name="android:windowActionBar"
才能工作适当地。所以我只是使用两者来确保以后需要移植到新的 Android 版本。I wanted to use my own theme instead of using @android:style/Theme.NoTitleBar.Fullscreen. But it wasn't working as some post on here had mentioned, so I did some tweaking to figure it out.
In AndroidManifest.xml:
In styles.xml:
Note: in my case I had to use
name="windowActionBar"
instead ofname="android:windowActionBar"
before it worked properly. So I just used both to make sure in the case I need to port to a new Android version later.KOTLIN
按照谷歌文档,有一个简单的方法:
谷歌文档
KOTLIN
Following the google doc, there is a easy way :
Google docs
要使您的活动全屏显示,请执行以下操作:
这将隐藏工具栏和状态栏。
但在某些情况下,您可能希望显示具有透明背景的状态栏,在这种情况下,请执行以下操作:
其他一些替代方法来隐藏工具栏而不是
getSupportActionBar().hide()
:android:theme="@style/Theme.AppCompat.Light.NoActionBar"
For kotlin爱好者,为什么不使用扩展函数:
第一种情况:
在
setContentView
之前调用:对于第二种情况:
在
setContentView
之前调用:To make your activity full screen do this:
This will hide the toolbar and status bar.
But In some case, you may want to show status bar with a transparent background, in that case, do this:
Some other alternate to hide toolbar instead of
getSupportActionBar().hide()
:<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
For kotlin lovers, why not use extension functions:
For first case:
And call this before
setContentView
:For Second One:
And call it before
setContentView
:截至 2022 年
As of 2022
提示:使用 getWindow().setLayout() 可能会搞乱您的全屏显示!请注意此方法的文档说:
http://developer.android.com/参考/android/view/Window.html#setLayout%28int,%20int%29
出于我的目的,我发现我必须使用带有绝对参数的 setLayout 来正确调整全屏窗口的大小。大多数时候,这工作得很好。它由 onConfigurationChanged() 事件调用。然而,有一个小问题。如果用户退出应用程序,更改方向,然后重新输入,则会导致触发包含 setLayout() 的代码。在此重新进入时间窗口期间,我的状态栏(被清单隐藏)将重新出现,但在任何其他时间 setLayout() 都不会导致这种情况!解决方案是在具有硬值的调用之后添加一个额外的 setLayout() 调用,如下所示:
然后窗口正确地重新调整大小,并且无论触发此事件的事件如何,状态栏都不会重新出现。
TIP: Using getWindow().setLayout() can screw up your full screen display! Note the documentation for this method says:
http://developer.android.com/reference/android/view/Window.html#setLayout%28int,%20int%29
For my purposes, I found that I had to use setLayout with absolute parameters to resize my full screen window correctly. Most of the time, this worked fine. It was called by an onConfigurationChanged() event. There was a hiccup, however. If the user exited the app, changed the orientation, and reentered, it would lead to firing off my code which included setLayout(). During this re-entry time window, my status bar (which was hidden by the manifest) would be made to re-appear, but at any other time setLayout() would not cause this! The solution was to add an additional setLayout() call after the one with the hard values like so:
The window then correctly re-sized, and the status bar did not re-appear regardless of the event which triggered this.
这对我有用。
It worked for me.
https://developer.android.com/training/system-ui/immersive。 html
活动:
AndroidManifests:
https://developer.android.com/training/system-ui/immersive.html
Activity :
AndroidManifests:
对于 kotlin,这就是我所做的:
沉浸模式
沉浸模式适用于用户将与屏幕进行大量交互的应用。例如游戏、查看图库中的图像或阅读分页内容,例如书籍或演示文稿中的幻灯片。为此,只需添加以下几行:
粘性沉浸式
在常规沉浸式模式中,每当用户从边缘滑动时,系统都会显示系统栏 - 您的应用程序甚至不会意识到该手势发生了。因此,如果用户实际上可能需要从屏幕边缘滑动作为主要应用程序体验的一部分(例如在玩需要大量滑动的游戏或使用绘图应用程序时),您应该启用“粘性”沉浸式模式。
详细信息:启用全屏模式
有关 键盘,有时会出现键盘出现时状态栏也显示的情况。在这种情况下,我通常将其添加到我的样式 xml
styles.xml
中,并将这一行添加到我的清单中
With kotlin this is the way I did:
Immersive Mode
The immersive mode is intended for apps in which the user will be heavily interacting with the screen. Examples are games, viewing images in a gallery, or reading paginated content, like a book or slides in a presentation. For this, just add this lines:
Sticky immersive
In the regular immersive mode, any time a user swipes from an edge, the system takes care of revealing the system bars—your app won't even be aware that the gesture occurred. So if the user might actually need to swipe from the edge of the screen as part of the primary app experience—such as when playing a game that requires lots of swiping or using a drawing app—you should instead enable the "sticky" immersive mode.
For more information: Enable fullscreen mode
In case your using the keyboard, sometimes happens that StatusBar shows when keyboard shows up. In that case I usually add this to my style xml
styles.xml
And also this line to my manifest
只需将此代码粘贴到
onCreate()
方法中Just paste this code into
onCreate()
method在 onCreate() 中的 setContentView 之后使用此方法,并通过 getWindow() 传递 Window 对象。
此代码也适用于凹口屏幕。要检查刘海屏全屏,您需要 Android P,但如果您有刘海屏手机,请转到设置-->显示设置-->应用程序显示比例-->选择您的应用程序 - --> 将有两个安全选项:显示和全屏,请选择全屏并运行应用程序,您也可以在刘海中看到全屏无需 Android Pie
Use this method after setContentView in onCreate() and pass the Window object by getWindow().
This code will work for notch screen also. To check the notch fullscreen you require android P but if You have a notch display phone then go to setting-->Display setting -->app display ratio --->select your app --->there will be two options safe are display and full screen , please select the full screen and run the app, you can see the fullscreen in notch also without having android Pie
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); if (getSupportActionBar() != null){ getSupportActionBar().hide(); }
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); if (getSupportActionBar() != null){ getSupportActionBar().hide(); }