How to detect if device support notch display?

前端 未结 2 499
梦谈多话
梦谈多话 2020-11-30 14:03

Currently I am facing a problem to detect if mobile device support notch display in android.

Can any one help me in this? (I need to do this using code in android s

2条回答
  •  伪装坚强ぢ
    2020-11-30 14:32

    You need to use the getDisplayCutout method of the WindowInsets object. This will give you a DisplayCutout object, which you can query to find the "safe" insets within the display.

    The DisplayCutout class is new in API level 28, so you won't be able to do it on devices with a lower API level (you can assume that there's no notch unless it's API level >= 28).

    There's a guide here.

    You can get hold of the WindowInsets object by overriding the onApplyWindowInsets method of the View, or by implementing a OnApplyWindowInsetsListener class.

提交回复
热议问题