Reputation: 365
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
}
Upvotes: 9
Views: 11611
Reputation: 590
you can use the tools target api
<item name="android:fontFamily" tools:targetApi="jelly_bean">sans-serif-light</item>
this will also work
<item name="android:fontFamily" tools:targetApi="17">sans-serif-light</item>
Upvotes: 13