how to set a Bitmap to background for a view Android API 10-18?
What I have is:
Manifest:
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="18" />
source:
View view = createViewFromWhatever();
Bitmap bitmap = loadSomethingAddMore();
Everywhere I have searched this is the accepted, suggested:
view.setBackgroundDrawable(new BitmapDrawable(bitmap));
But it is Deprecated in API 18. I am terrorised with framework bugs and
miss documentations at OS level. I want to respect what they are saying
and in case of crash "it is not my fault"
I can't even use the new BitmapDrawable(bitmap) and I need new
BitmapDrawable(getActivity().getResources(), bitmap) instead. If I change
my method to a recommended way: setBackground(new
BitmapDrawable(getActivity().getResources(), bitmap));
It will mark as error with message:
Call requires API level 16 (current min is 10):
android.widget.RelativeLayout#setBackground
As a solution I could check what version is running the user and do an
if-else than I will have a code will with if(isAndroidVersion10()) else if
() ...
Any solution acceptable solution?
If I escape from deprecation warnings via reflection I still will have the
responsibility in case of crash, because I have release the code with
deprecated method! -just the way how I call is different.
If I ignore that Lint, than it will crash at a low version api, tested.
No comments:
Post a Comment