当前位置:网站首页>Support liuhaiping
Support liuhaiping
2022-07-24 12:30:00 【Sharp surge】

Fringe screen refers to an area on the display screen of some equipment extending to the display surface , This can provide users with a comprehensive screen experience , It can also leave space for important sensors on the front of the equipment .Android On board Android 9(API Level 28) And later devices officially support Liu Haiping . Please note that , Equipment manufacturers can also choose to carry Android 8.1 Bangs are supported on devices at or below .
This topic describes how to support devices with bangs , Including how to deal with “ Bangs area ”, That is, the borderless rectangle containing bangs on the display surface .
What are the requirements on the equipment with bangs
To ensure consistency and application compatibility , carrying Android 9 The equipment must ensure the following bangs :
- An edge can contain at most one bangs .
- A device cannot have more than two bangs .
- There shall be no bangs on the two longer edges of the equipment .
- In vertical screen mode without special signs , The height of the status bar must be at least equal to the height of the bangs .
- By default , In full screen mode or horizontal screen mode , The entire fringe area must show a black edge .
Choose how your app handles bangs
If you don't want your content to overlap with the bangs area , Make sure your content doesn't overlap the status bar and navigation bar , This is generally enough . If you want to present the content in the bangs area , You can use WindowInsets.getDisplayCutout() To search DisplayCutout object , This object contains the security lining area and bounding box for each fringe area . You can use these API To check if your content overlaps the bangs area , To reposition as needed .
Be careful : In multiple API Level management bangs achieve , You can also use it AndroidX library ( It can be done by SDK Manager gets ) Medium DisplayCutoutCompat.
Android It also allows you to control whether content is displayed in the fringe area . Window layout properties layoutInDisplayCutoutMode Control how your content is rendered in the bangs area . You can use layoutInDisplayCutoutMode Set to one of the following values :
- LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT - This is the default behavior , As mentioned above . In vertical screen mode , The content will be presented in the fringe area ; But in landscape mode , The content will show a black edge .
- LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES - In vertical screen mode and horizontal screen mode , The content will be presented in the fringe area .
- LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER - The content is never presented in the bangs area .
You can program or in Activity Set style in to set bangs mode . The following example defines a style , You can use it to LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES Property applied to Activity.
<style name="ActivityTheme"> <item name="android:windowLayoutInDisplayCutoutMode"> shortEdges <!-- default, shortEdges, never --> </item> </style>
The following sections describe the different bangs patterns in more detail .
Default behavior
By default , In vertical screen mode without special signs , On a device with a banged screen , The size of the status bar will be adjusted to be at least as high as the bangs , Your content will be displayed in the lower area . In landscape mode or full screen mode , Your application window will show a black edge , Therefore, nothing of your content will be displayed in the bangs area .
Present the content in the short fringe area
For some content ( Video frequency 、 Photo 、 Maps and games ), It's a good way to present in the fringe area , This can provide users with a more immersive and comprehensive screen experience . If set LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES, In vertical screen mode and horizontal screen mode , The content will extend to the fringe area on the short side of the display , Regardless of whether the system bar is hidden or visible . Please note that , The window cannot extend to the fringe area on the long side of the screen . When using this mode , Please make sure that no important content overlaps with the fringe area .
Please note that ,Android The content view may not be allowed to overlap the system bar . To replace this behavior and force the content to extend to the fringe area , Please pass View.setSystemUiVisibility(int) Method applies any of the following flags to view visibility :
- SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
- SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
- SYSTEM_UI_FLAG_LAYOUT_STABLE
Here are some LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES Example :

Please note that , Bangs at the corners can be equivalent to bangs on the short sides , So the same behavior applies :

Never present content in bangs
If set LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER, The window is not allowed to overlap with the fringe area .
This mode should be used to temporarily set View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION The window of , To avoid performing another window layout when the flag is set or cleared .
Please check the following LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER Example :

Special mode
Some carry Android 8.1(API Level 27) Or earlier devices support a special mode , Allows the user to extend the full screen or horizontal screen application with black edge to the fringe area . This mode is usually controlled using the toggle switch in the navigation bar , A dialog box appears before extending the screen , Ask the user to confirm .

Support Liu Haiping's best practices
Use Hai Ping Liu when , Please be sure to consider the following points :
- Don't let the fringe area cover any important text 、 Control or other information .
- Do not place or extend any interactive elements that require fine touch recognition to the fringe area . The touch sensitivity in the fringe area may be lower than that in other areas .
Avoid hard coding the status bar height , Because doing so may cause the content to overlap or be cut off . If possible , Please use WindowInsetsCompat Retrieve the status bar height , And determine the appropriate margin to apply to your content .

Don't assume that the application will occupy the entire window , And should be used View.getLocationInWindow() To confirm the location of the application . Do not use View.getLocationOnScreen().
Be sure to properly handle entering or exiting full screen mode . Please read This article Android Developer blog .
For default bangs behavior in vertical mode , If the fringe area is at the top edge , And the window is not set FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_FULLSCREEN, Then the window can extend to the fringe area . Again , If the fringe area is at the bottom edge , And the window is not set View.SYSTEM_UI_FLAG_HIDE_NAVIGATION, Then the window can extend to the fringe area . In full screen mode or horizontal screen mode , The layout of the window shall be such that it does not overlap the fringe area .
If your application needs to enter and exit full screen mode , Please use
shortEdgesorneverBangs pattern . The default fringe behavior can cause the content in the application to move up and down during the full screen mode conversion , As shown in the figure below :

In full screen mode , Care should be taken when using window and screen coordinates , Because when the black edge is displayed , Your app won't occupy the entire screen . Because the black edge is displayed , Therefore, the coordinates obtained from the screen origin are no longer the same as those obtained from the window origin . You can use getLocationOnScreen() Convert screen coordinates to view coordinates . The following figure shows how the two coordinates are different when the content is displayed with a black edge :

Handle MotionEvent when , Please use MotionEvent.getX() and MotionEvent.getY() To avoid similar coordinate problems . Do not use MotionEvent.getRawX() or MotionEvent.getRawY().
Test how your content is rendered
Be sure to test all the screens and experiences of the application . If possible , Test on equipment with different types of bangs . If you don't have a device with bangs , You can carry Android 9 Simulate some common bangs configurations on any device or Simulator , The specific operation steps are as follows :
- Enable Developer options .
- stay Developer options On screen , Scroll down to the drawing section , Then select simulate bangs .
- Select bangs type .

Other resources
For more information about liuhaiping support , Please refer to the following links :
- android:windowLayoutInDisplayCutoutMode
- DisplayCutout
- layoutInDisplayCutoutMode
- WindowInsets
- WindowInsets.getDisplayCutout()
from : Support Liu Haiping | Android developer | Android Developers
边栏推荐
- js图像转base64
- 向勒索病毒说不,是时候重塑数据保护策略
- Taishan Office Technology Lecture: layout difficulties of paragraph borders
- Zhihuihuayun | cluster log dynamic collection scheme
- QWaitCondition 的正确使用方法
- [mathematical basis of Cyberspace Security Chapter 3] congruence
- Quick check list of various XSS payloads
- Common shortcuts to VIM editor
- Okaleido tiger NFT即将登录Binance NFT平台
- Equal principal increasing repayment / equal principal decreasing mortgage repayment calculator
猜你喜欢

Use abp Zero builds a third-party login module (III): web side development
![[rust] what software should I use to develop rust? Recommended editors commonly used to support rust](/img/a8/becbf7dc059939120a6bc632fe8708.png)
[rust] what software should I use to develop rust? Recommended editors commonly used to support rust

Industry insight | how to better build a data center? It and business should "go together"

Qt Creator怎样更改默认构建目录

Install JMeter

Day3: branch structure

Wechat official account development: Material Management (temporary and permanent)

支持刘海屏

Wechat applet generates QR code

从零实现深度学习框架——再探多层双向RNN的实现
随机推荐
Common shortcuts to VIM editor
Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]
Implementing deep learning framework from zero -- further exploration of the implementation of multilayer bidirectional RNN
Force deduction exercise - 26 split array into continuous subsequences
Buckle exercise - 35 combination sum II
Basic SQL server operation problems - only when lists are used and identity_ Only when insert is on can the display value be set for the identification column in the table
我在一个模块工程中使用注解配置了redis的序列化, 然后在另外一个模块引入这个模块,为什么这个配置
如何用WebGPU流畅渲染百万级2D物体?
QT notes - custom data types
Skillfully using command line parameters in Delphi to realize the trigger function of dragging files onto program icons
String matching KMP
With the strong development of cloud native, how should enterprises seize business opportunities
Ansible的安装及部署
The biggest crisis for testers in the workplace is not at the age of 30, but being laid off in middle age
Force deduction exercise - the sum of the kth smallest array in the 21 ordered matrix
Use abp Zero builds a third-party login module (III): web side development
One of his birds sold for 60million -- the collection of eight mountain people in the Ming and Qing Dynasties
如何在IM系统中实现抢红包功能?
Zhihuihuayun | cluster log dynamic collection scheme
Buckle practice - 25 non overlapping intervals