I'm trying to implement ViewOutlineProvider in my project for set a shadow in my tab, but the logcat said me to change API level version to 21. (my min API version is 15) Are you advice this?
Thanks!
That's because ViewOutlineProvider support API>21, you can use if statement to apply this feature for devices with an API higher that 21 :
if(Build.VERSION.SDK_INT >= 21){
// set shadow ....
}
Related
My app is running well in API 23 and above, but there seems to be a bug in it when I run it in API 21. I've narrowed it down to this piece of code:
if (myButton.getBackground().getConstantState() == ResourcesCompat.getDrawable(getResources(), R.drawable.myDrawable, null).getConstantState())
{...}
In API 21 it always returns false (even when it shouldn't), so I guess one of those methods doesn't work in API 21.
Any ideas? Is there any other way (compatible with API 21 and above) to check if a button's background has a specific drawable assigned to it?
ps: my minsdk is 21, but Lint is not giving me any warnings.
You can try using ContextCompat:
ContextCompat.getDrawable(yourContext, R.drawable.myDrawable).getConstantState();
Does anyone know if ViewCompat.setLayoutDirection works in API level below 17?
I search for a solution all over the internet but I can't find a solid one.
setLayoutDirection was added to in API Level 17 (read here) which is 4.2 so the older versions do not support that. So keep two layouts for higher and below and you need to work around for the below api level XML view.
If you're using the support library, you can do the following:
if (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL) {
// view -RTL layout
} else {
//view - set made layout for below apis
}
BidiFormatter might help you depending on your requirement.Check that as well.
Every one knows about android:layout_gravity="end" right? can be helpfull in this case
I need to delete app from recently used apps list. There is no problem on API level 21 and above. I use finishAndRemoveTask() method. But that method cannot be used on API levels lover than 21. How can I call that method on API levels lover than 21?
I tried that solutions but they does not work :
Close application and remove from recent apps/
Prease, check code below
if (Build.VERSION.SDK_INT >= 21)
finishAndRemoveTask();
else
finish();
System.exit(0);
I solved the problem with that library :
https://github.com/Ereza/CustomActivityOnCrash
How to use
txtV1.setBackground(getResources().getDrawable(R.drawable.bcgrtxt));
in Older Devices ?
View.setBackground replaced View.setBackgroundDrawable as of API level 16.
.setBackground was added in API Level 16
and .setBackgroundResource was added in API Level 1
so you can use .setBackgroundResource instead of .setBackground
In an Activity I have a code that shows this error, but only if you press save.
Call requires API level 11 (current min is 8): android.widget.SearchView#setSearchableInfo
If I change the android:minSdkVersion to 7, it works, but when I save the code again, the same error is thrown. The minSdk must then be changed back to 8,...
What is wrong?
SearchView is available since API lvl 11.
Since your minimum sdk is 8 (lower than 11), Lint will give an error when using SearchView.
You can remove that error by using #TargetApi annotation before your method or class.
But you have to make sure you use a conditional statement before using SearchView to check if it is available, and provide an alternative for earlier versions.
Here's what your code should look like:
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
void yourMethod(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
// use SearchView
} else {
// use some other backward compatible custom view
}
}
The SearchView exists in Android from the version 11 ant more.
So, if you would like to use the SearchView in your code, you have to put the minSdkVersion in your manifest to be 11. In the case you put a number smaller than 11, you will get an error, which is normal beause you are giving access to your app to some android versions which will not support your app.
This can be seen (thanks to #JesseJ) here: http://developer.android.com/reference/android/widget/SearchView.html
Added in API level 11