Reputation: 4081
I have a problem with getBackground() and setBackground() method. I have designed an application, but now I found out that I didn't check which version is user android system (I am beginner to android - good lesson).
My aplication is working on Build.version > 15, because methods mentioned above were introduced in this version.
I would like to use similar method that existed before version 16. Any ideas?
Upvotes: 0
Views: 688
Reputation: 45493
The getBackground()
method has been around since API level 1, so that shouldn't be a problem. Only setBackground(Drawable background)
was introduced starting API level 16 and may thus cause problems on older platforms.
Your alternatives are:
setBackgroundColor(int color)
setBackgroundDrawable(Drawable background)
setBackgroundResource(int resid)
Of these methods, the second one has been deprecated since API level 16, as it was replaced with the setBackground(Drawable background)
you're currently using. However, if you look at the actual implementation for that method, you'll see the following:
public void setBackground(Drawable background) {
//noinspection deprecation
setBackgroundDrawable(background);
}
So all it does at this point is delegate the call to the deprecated setBackgroundDrawable()
method. Hence, if you want a quick fix, just change your code to use that one and you're good to go.
Upvotes: 3