2

Is there any way to import the curved edges from the device into an app?

As you can see in this link, some devices have the screen itself withcurved edges, but when I open my app in those devices, the edges turn to straight corners and fill the screen. I hate the inconsistency and want to mimic the screen curves within the app. I can guess the extent of the curves in dp and incorporate it myself, but I only want the curves in devices where it is the default. So I want to know if there is any way to get the curve information from from the device and apply it to the app directly so that devices with curved corners would have the curves within the app, and other devices with straight corners would have straight edges in the app?

MohanKumar
  • 960
  • 10
  • 26
blankface
  • 41
  • 1
  • I'd suggest you look into using a 9-patch with rounded corners as the background for your Activities. I also guess your app's background will need to be black in your theme. – kenny_k Oct 01 '19 at 07:02

1 Answers1

0

I think the OP wanted to know if the display of the device on which his app is running has rounded corners, and if so, how big they are.

If the device's OS is Android Snow cone (Android ver. 12, API 31) or later, this code will find out:-

    private int getCornerAllowance() {
        int i = 0;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            Display disp = getDisplay();
            RoundedCorner rc = disp.getRoundedCorner(
                RoundedCorner.POSITION_BOTTOM_LEFT);
            int j = rc.getRadius();
            if (j > i) { i = j; }
            rc = disp.getRoundedCorner(
                RoundedCorner.POSITION_BOTTOM_RIGHT);
            j = rc.getRadius();
            if (j > i) { i = j; }
            rc = disp.getRoundedCorner(
                RoundedCorner.POSITION_TOP_LEFT);
            j = rc.getRadius();
            if (j > i) { i = j; }
            rc = disp.getRoundedCorner(
                RoundedCorner.POSITION_TOP_RIGHT);
            j = rc.getRadius();
            if (j > i) { i = j; }
        }
        return i;
    }

If you want to set the padding of a rectangular view so that it will be entirely inside the rounded corners, multiply the returned value by 3/10 and set the padding in all four directions to the result.

If you know that there is a status bar at the top of the screen, you don't need to set padding in that direction

Community
  • 1
  • 1
Richard Parkins
  • 347
  • 2
  • 13