I am developing an app for Card View.Implement two features of card view "setRadius()" and "setElevation()" .It is working fine in Android L.
But when I run the app in API 19 (KitKat) , card view setElevation() getting an error
java.lang.NoSuchMethodError: android.view.View.setElevation"
Can any one please help me to make this app compatible to all version.
possible duplicated.
Android AppCompat 21 Elevation
Basically setElevation from ViewCompat won't even work.
Take a look at the docs for setElevation and you can see that it was added in API 21 (which is Lollipop).
You can, however, use the ViewCompat library's version of setElevation, and then it should work on lower API levels.
Related
AS 4.0.1
Use app:drawableEndCompat instead of android:drawableEnd warning on API 21 and above
<TextView
android:id="#+id/tvCheckStock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/ic_pin_drop
android:gravity="center_vertical"/>
The ic_pin_drop is a SVG (Vector Drawable) that was created using Android Studio File | New | Vector Asset | Configure Vector Assert
In my Build.gradle file I have the following configuration:
minSdkVersion 21
targetSdkVersion 29
vectorDrawables.useSupportLibrary true
As the min is API 21 which is Lollipop I was thinking that vector drawables are supported out of the box and we can use the DrawableEnd, DrawableStart etc without the compat versions?
I was thinking that the compat versions were for pre 21 API level. Kitkat and below. And as I am not targeting that minimum I am not sure why I am getting that warning.
This would result in a cash on those devices less than 21 if the compat version is not used.
Many thanks for any suggestions.
The primary motive behind this warning is to make your VectorDrawables look same on all devices by making them backward compatible.
By using "Compat", you would be ensuring that using your vector asset would not crash your app for devices below API 21(Lollipop). In short, using drawableEndCompat would allow anyone to use the same features of drawableEnd on older APIs(<21).
Now you would be thinking that what should I choose:
If you are using drawableEndCompat, it would work as you expect in every device. Devices with API more than 21 would internally unwrap them as normal drawableEnd as far as I know.
If you choose to use drawableEnd, it will be working for API 21 and above only.
If you think that I don't need any Compat Support : You may increase your application's minimum SDK from current value to atleast 21. Then you can use keyword drawableEnd peacefully without any warning.
Also, you may opt to create different layout file for different APIs under which in layout file for below API 21, use drawableEndCompat and for API 21 and above use drawableEnd. In my opinion, you can also check whether you can use both attributes at same place. I feel like that they can work together as well.
If you are not supporting devices below API 21, there is no problem: You should have no issues/warning. Also, one more thing I need to tell you - Android Studio sometimes throw warnings or bugs; even if you are right. In that case, if you feel that you were correct, you should try invalidate/restart option after clicking File option in Menu Bar. I would also suggest to try restarting your system to everyone who are using system for long durations or always keeping it on sleep mode.
So, for a TextView, you should use app:drawableEndCompat (or start, top, bottom) instead of app:drawableEnd
Vector drawables are supported since API 21 but new features are added over time, even to vector drawables. It may be a good idea to use AppCompat and not worry about that.
Tinting compound drawables on TextViews was added in API 23. The suggestion is pushing you towards the compat variant, where the feature is backported.
app:drawable*Compat
app:drawableTint and app:drawableTintMode
If you don't use compound drawable tinting you may be fine with the platform version of the attributes.
android:drawable*
android:drawableTint and android:drawableTintMode (added in API 23)
could anyone please help me with this?
I opened an existing project and I get this error in the screenshot.
The problem is that you are using a style which require API 21. You are referencing a style called Widget.Material.ActionButton. So you need to put this reference in a v21 directory to use the CompatLibrary which I would recommend.
The real cause seems to be that you have a very low target SDK (like you wrote in the comments API 8). You should set it to the most newest one, it cannot break anything. So set the target SDK to API 21 or newer and it should work fine.
Whenever I create a blank activity layout file assigned to be rendered at API level 22, following error message is generated
The solution to this is to change the API level by changing it to API 21 or less.
What is the reason behind this?.
This was very common for me when a new API SDK version was released and yes like you mention we have to change the Android version to use when rendering layout in the IDE.
But this time i have installed all the elements described in the Android SDK Manager for this API 22 and I have no problems with the rendering.
You can just change "AppTheme" to another theme and keep the API level as you desire.
Many users are reporting this problem and it happens only in the Layout files that uses support libraries and not the normal ones.
I want to use circular-progress-button on android 2.2 or above. But there is a error on Property class that say minimum sdk must be 14.
I don't want to check sdk version and then use or not.
Or even is there any alternative library like this?
If you want to remove that error maybe you need to increase android:minSdkVersion to 14, which means you cant support bellow Android 4.0.
But there is another library with android:minSdkVersion=11. You can use that library too. Here is the link:
FABProgressCircle
Can you explain to me how I should determine the correct value for targetSdkLevel?
Let's say I want to build an app that works on all the versions from android 2.3.7 to 4.0.3, how should I set minSdkLevel and targetSdkLevel?
The former should match the API level of android 2.3.7 and the latter should match the API level of 4.0.3?
Then, when I develop my app, should I use only Methods/classes available in the oldest supported sdk level?
When I compile the app does it compile for 2.3.7 or 4.0.3?
I can not understand the purpose of targetSdkLevel, since the apk can not be compiled for the newer version specified in this tag, otherwise it could not work on versions down to the one specified by minSdkLevel... Why should I not set targetSdkLevel to the latest available level?
I've read also the official info about uses-sdk Manifest tag, but I still do not understand.. Can you help me clarifying this topic?
EDIT: thanks to all of you and excuse me for the duplicate question. I've read this Blog post and it really helped me. Great answers from all of you.
You should only use methods/classes available in the SDK specified by minSdkLevel, or otherwise wrap them with a proper check for the runtime API version.
Your application will be compiled with the SDK specified in the project itself, not by the one specified by either minSdkLevel nor targetSdkLevel.
You should set targetSdkLevel to the highest level API that you have tested the application with. This is because compatilibity behavior will be enabled/disabled for your application based on this value.
It clearly is explained here: http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
minSdkVersion:
An integer designating the minimum API Level required for the
application to run. The Android system will prevent the user from
installing the application if the system's API Level is lower than the
value specified in this attribute. You should always declare this
attribute.
And for targetSdkVersion
An integer designating the API Level that the application targets. If
not set, the default value equals that given to minSdkVersion. This
attribute informs the system that you have tested against the target
version and the system should not enable any compatibility behaviors
to maintain your app's forward-compatibility with the target version.
The application is still able to run on older versions (down to
minSdkVersion).
What is that you don't understand here?
This is how you would set it:
<uses-sdk android:minSdkVersion="10"
android:targetSdkVersion="15"/>
You can read about the changes here, for API Level 14: http://developer.android.com/sdk/api_diff/14/changes.html
and here for API Level 4: http://developer.android.com/sdk/api_diff/4/changes.html
Build using the target, and then you can check and gracefully downgrade if the user is below the target. For example, if you are creating a location aware app, you might want to use PASSIVE_PROVIDER which is available starting with version 8. You could set the min version lower than 8 and check the android version. From there you could decide to use or not use PASSIVE_PROVIDER based on the version.
google suggests that you always use the latest version of the targetSdk , and also gives the lint tool to check for you that your classes and methods aren't too new for the minSdkVersion .
in case of a warning , you will need to think of how to handle it.
do note that as people has mentioned here , setting the targetSdk also means that it will change some aspects of the app .
one aspect is how the app treats the menu button : if you set the targetSdk to 11 or above , it means that you can't assume that there is a menu button , so you will have to deal with the action bar and put the options there in some way (or any other way, depending on your app design) .
if you set it to 10 or below , android will add this button (shown as 3 dots) on the screen for devices that don't have the menu button , like the htc one x or the galaxy nexus . do note that for some devices it looks ugly (takes a whole row for the htc one x , for example) .
so , in short , i would suggest setting the minSdk to the minimum that you can , in order to support as many people as possible , and the targetSdk to the maximum that you can , in order to enjoy all of the benefits that it can give you .