Home » Android » android – Using attributes from API level beyond minSdkVersion

android – Using attributes from API level beyond minSdkVersion

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am new to Android development and am wondering what happens if you use attributes on XML tags from an API level greater than your minSdkVersion.

For example having:

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="20" />

And then using this:

<activity android:logo="@drawable/iconwhatever"></activity>

The “android:logo” attribute is from API level 11.

In Android Studio it gives the following error, but I want to know what could happen if this is left alone:

Attribute "logo" is only used in API level 11 and higher. (Current min is 9)

Any help regarding this would be greatly appreciated.

How to&Answers:

Unsupported attributes are safely ignored.

From SDK documentation:

When parsing XML resources, Android ignores XML attributes that aren’t supported by the current device. So you can safely use XML attributes that are only supported by newer versions without worrying about older versions breaking when they encounter that code.

Answer:

For XML attributes, its safe to use attributes from newer APIs (they will simply be ignored as the XML parser won’t even look for them on older versions).

Answer:

In this case, the manipulation of attributes that are different APIs must be made via code and not in XML.

In code, you can treat it.

For example:

 if(Build.Version.SDK_INT > 10){

     .... use an attribute

   }
else{

    .... use other
}

For your specific case, use “icon”

<activity android:icon="@drawable/iconwhatever"></activity>