I needed to add a digital clock
in the layout. My min-supported
API level is 14. I found out that there is a digital clock
widget for API level below 17 (After that it got deprecated), and there is a text clock
for API 17 and above.
So one thing I can do is to add both layout in xml and dynamically set the visibility based on version number in the code. But the xml will continuously show me that I have used Text Clock
while my min-supported
level is 14. So:
Is there a way in the xml to specify to ignore the min-sdk
error. Something like
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
That we use in the normal java code.
Is there a way in XML to specify to use a particular widget based on version number. Some kind of if else statement in the xml that says:
if((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
//Use text clock
} else {
// Use digital clock
}
When you upload an APK, it must meet Google Play's target API level requirements. New apps must target Android 12 (API level 31) or higher; except for Wear OS apps, which must target Android 11 (API level 30) or higher.
android:minSdkVersion — Specifies the minimum API Level on which the application is able to run. The default value is "1". android:targetSdkVersion — Specifies the API Level on which the application is designed to run.
It is the minimum SDK version that the app support. It is defined in build. gradle file. For example, if you set the minSdk to 30, an SDK version corresponds to API Level 30 and Android 11. It makes your app run only on devices with Android 8 or higher versions.
If you want to show different layout depending api version, you can also name your resource folders to indicate version number like
/res/layout/layout.xml (Default)
/res/layout-v14/layout.xml
/res/layout-v17/layout.xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With