【发布时间】:2019-03-13 23:40:47
【问题描述】:
这是一个简单的代码,错误消息并没有说明不推荐使用的确切位置。
package com.dev.marcellocamara.pgm.Helper;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.dev.marcellocamara.pgm.R;
public class CardHelper {
public static Drawable getBackground(Context context, int drawable){
switch (drawable){
case 1 : {
return (context.getResources().getDrawable(R.drawable.card_yellow));
}
case 2 : {
return (context.getResources().getDrawable(R.drawable.card_purple));
}
case 3 : {
return (context.getResources().getDrawable(R.drawable.card_green));
}
default : {
return null;
}
}
}
public static Drawable getFlag(Context context, int flag) {
switch (flag){
case 1 : {
return (context.getResources().getDrawable(R.drawable.flag1));
}
case 2 : {
return (context.getResources().getDrawable(R.drawable.flag2));
}
case 3 : {
return (context.getResources().getDrawable(R.drawable.flag3));
}
default : {
return null;
}
}
}
public static int getColor(Context context, int card) {
switch (card){
case 1 : {
return (context.getResources().getColor(R.color.card1));
}
case 2 : {
return (context.getResources().getColor(R.color.card2));
}
case 3 : {
return (context.getResources().getColor(R.color.card3));
}
default : {
return 0;
}
}
}
}
正如代码所说,我正在返回可绘制对象或颜色。这很简单。需要更改的警告在哪里,如何跳过此警告,继续返回可绘制对象和颜色?
【问题讨论】:
标签: java android-studio colors drawable deprecated