Android getDrawable()和getColor()

Android getDrawable()

1.过时代码

虽然过时,但是不妨碍使用

context.getResources().getDrawable(R.drawable.xxx)

2.建议代码

context.getDrawable(R.drawable.xxx)

有API限制

3.最新代码

ContextCompat.getDrawable(getContext(), R.drawable.xxx);

有API限制

4.最最新

Drawable drawable= AppCompatResources.getDrawable(context,R.drawable.xxx);

5.getColor()

getColor()和getDrawable()一样的

6.其他

直接使用getColor()和getDrawable()会让我们选择导入的方法

猜你喜欢

转载自blog.csdn.net/fromVillageCoolBoy/article/details/132006837