Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use XML attribute paddingHorizontal on pre API 26 devies?

Is the XML attribute android:paddingHorizontal that was introduced in API 26 (Android O) only available in 26 and above? Is there a support version of it? I require my minSdkVersion to be much lower than 26.

I’m under the impression that the Android Asset Packaging Tool 2.0 (AAPT2) , that’s been included in Android Studio 3, could possibly help out with this.

From the release AAPT2 release notes:

Version 2.16

aapt2 link ...

Versioning of XML files is more intelligent, using a small set of rules to degrade specific newer attributes to backwards compatible versions of them. Ex: android:paddingHorizontal degrades to android:paddingLeft and android:paddingRight.

But have not idea how to use AAPT2, and I’m not finding much information out there on how to you it, I just see mentioning of it. Is my request even possible?

Any help/answers are greatly appreciated.

Update: Yeah, it doesn’t work on lower SDK versions.

like image 837
Sakiboy Avatar asked Nov 11 '17 12:11

Sakiboy


2 Answers

Although paddingHorizontal, paddingVertical, layout_marginHorizontal andlayout_marginVertical were introduced in API 26 (Android O), they can be used safely when targetting older SDK versions thanks to the desugaring performed by aapt2 (added in v2.16) that converts these to left/right or top/bottom automatically at build time.

Note: sadly they are not supported in styles (nor planned to be) (ref).

like image 100
David Miguel Avatar answered Sep 19 '22 23:09

David Miguel


paddingHorizontal and paddingVertical is indeed introduced with API 26 (O). See the Android O update note for proof: https://developer.android.com/about/versions/oreo/android-8.0

like image 24
user690421 Avatar answered Sep 20 '22 23:09

user690421