Pages

Thursday, March 10, 2016

Rounded corners problems/error in android sdk prior to v12

So i had a problem when rounded corners were broken on lower sdk's.

For example, you made a drawable/selector/etc for your button with rounded corners on the left and not rounded on the right. Like on picture (1).


If you check how it looks on a device with sdk prior to 12 (I checked on a genymotion 2.3.7 android device), the button will look something like (2). Because, apparently, there is a bug that flips bottom corners.

The fix is very easy. Specify rounded corner values in the dimens.xml file and use them like android:padding="@dimen/attr1" this. Create a values-v12 folder and make a dimens.xml file there.

Sample contents:
<resources><dimen name="name">10dp</dimen></resources>


Here, specify the correct values for each rounded corner. For (1) it would be 0dp for top right, 0dp for bottom right, 10dp for top left, 10dp for bottom left corners.

These values will be used on devices starting with sdk lvl 12.

So in the original dimens.xml you should specify the fixed values to workaround the bug, swap places the bottom corners like this: 0dp top right, 10dp bottom right, 10dp topleft, 0dp bottom left.

This will result in a shape (1).

Oh, btw, the preview in Android Studio anyway shows gibberish with the corners, just ignore it.


No comments:

Post a Comment