Hide and show only status bar keeping the content is full screen mode in Android 12 [without depreciate code]

huangapple go评论57阅读模式
英文:

Hide and show only status bar keeping the content is full screen mode in Android 12 [without depreciate code]

问题

I want to achieve behaviour similar to video attached below from the WEBTOONS app, where content is in full screen and they hide and show status bar:

Video of required behaviour

APP ref link

I want to achieve this behaviour in API Level 23 to 31.

What is the correct way to achieve this behaviour without using deprecated code?

Thanks

I have tried multiple solutions as mentioned below but none of them give the required behaviour, and also a few methods below are deprecated.

UPDATE

I am able to achieve the required behavior only on devices without a notch using this code function, but it fails for devices with a notch. The content won't get covered under the status bar in full-screen mode, giving a black space in the status bar region.

I tried this method but it didn't help.

And also, the content resizes as I exit full-screen mode, and the content goes under the visible status bar.

Above code is deprecated in API level 30. I would appreciate it if you could share the exact non-deprecated alternative code.

UPDATE2

I was able to find the solution for all Android versions as mentioned here. For more details, refer to this answer.

英文:

I want to achieve behaviour similar to video attached below from the WEBTOONS app, where content is in full screen and they hide and show status bar

Video of required behaviour

APP ref link

I want to achieve this behaviour in API Level 23..to..31

What is the correct way to achieve this behaviour without using deprecated code ?

Thanks

I have tried multiple solutions as mentioned below but none of the gives the required behaviour and also few methods below are deprecated.

            WindowManager.LayoutParams.FLAG_FULLSCREEN)

-> requireActivity().window.setFlags(LayoutParams.FLAG_LAYOUT_NO_LIMITS, LayoutParams.FLAG_LAYOUT_NO_LIMITS)

-> windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())

-> requireActivity().window.setDecorFitsSystemWindows(false)

-> requireActivity().window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN

UPDATE

I am able achieve the required behaviour only on Devices without notch using this code
function

but fails for the devices with notch ,content wont get covered under status bar in full screen mode gives a black space in the status bar region

tried
tried method
but didn’t help

And also content resizes as I exit full screen mode content goes under visible status bar

Above code is deprecate in API level 30 appreciate if could share exact non-deprecated alternative code

UPDATE2

was able to find the solution for all android versionas mentioned here

for more details refer this answer

答案1

得分: 0

你需要为窗口设置以下标志:

window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

SYSTEM_UI_FLAG_LAYOUT_STABLE:此标志表示应用程序的稳定内容应显示在系统栏(状态栏和导航栏)的后面。它允许您的应用程序使用通常由系统栏占用的空间,以使您的内容在系统栏隐藏或显示时不会调整大小。

SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN:此标志表示应用程序希望占用整个屏幕,包括系统栏后面的空间。当设置了此标志时,您的应用程序的内容可以延伸到通常保留给屏幕顶部状态栏的区域。

希望对您的情况有所帮助。

英文:

You need to set following flags for window

window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

SYSTEM_UI_FLAG_LAYOUT_STABLE : This flag indicates that the application's stable content should appear behind the system bars (status bar and navigation bar). It allows your application to use the space normally occupied by the system bars so that your content doesn't resize when the system bars hide or show.

SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN : This flag indicates that the application wants to occupy the entire screen, including the space behind the system bars. When this flag is set, the content of your application can extend into the area normally reserved for the status bar at the top of the screen.

I hope it will work for your scenario

答案2

得分: -1

找到了所有 Android 版本的解决方案如此处所述
有关更多详细信息,请参考此答案

英文:

was able to find the solution for all android version as mentioned here
for more details refer this answer

huangapple
  • 本文由 发表于 2023年6月13日 13:03:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76461815.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定