的setBackground VS setBackgroundDrawable(安卓) [英] setBackground vs setBackgroundDrawable (Android)

查看:194
本文介绍了的setBackground VS setBackgroundDrawable(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个视图背景绘制。有两种方法为这个(据我看到的):的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.

这篇关于的setBackground VS setBackgroundDrawable(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆