的setBackground VS setBackgroundDrawable(安卓)setBackground、VS、setBackgroundDrawable

由网友(寒兮念红颜°)分享简介:我想设置一个视图背景绘制。有两种方法为这个(据我看到的):的setBackground和setBackgroundDrawable。当我使用的setBackground,这我说,它已经在API级16增加了,但我的项目的最小SDK版本为7。我认为它不会工作在任何16岁以下,是对的?但是当我使用setBackgroundD...

我想设置一个视图背景绘制。有两种方法为这个(据我看到的):的setBackground和setBackgroundDrawable。当我使用的setBackground,这我说,它已经在API级16增加了,但我的项目的最小SDK版本为7。我认为它不会工作在任何16岁以下,是对的?但是当我使用setBackgroundDrawable,它说,这是德precated。

I want to set background drawable of a view. There are two methods for this (as far as I see): setBackground and setBackgroundDrawable. When I use setBackground, it says it has been added in API level 16 but my project's min SDK version is 7. I assume it's not going to work on anything below 16, am I right? But when I use setBackgroundDrawable, it says it's deprecated.

我该怎么使用?

推荐答案

这是pcated德$ P $,但它仍然有效,所以你可以只使用它。但是,如果你想成为完全地正确的,只是它的完整性......你会做类似如下:

It's deprecated but it still works so you could just use it. But if you want to be completly correct, just for the completeness of it... You'd do something like following:

int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
    setBackgroundDrawable();
} else {
    setBackground();
}

对于这个工作,你需要设置buildTarget API 16分钟打造以7或类似的东西。

For this to work you need to set buildTarget api 16 and min build to 7 or something similar.

阅读全文

相关推荐

最新文章