我的 class 代码中弃用的 API 在哪里?我想不通
Where is the deprecated API at my class code ? I can't figure out
这是一个简单的代码,错误消息没有说明弃用用法的确切位置。
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;
}
}
}
}
正如代码所说,我正在返回可绘制对象或颜色。这很简单。需要更改的警告在哪里,如何跳过此警告,继续返回可绘制对象和颜色?
在 Android API 22 getResources().getDrawable()
中已弃用。现在你应该使用这个方法 getDrawable (int id, Resources.Theme theme)
并且 getColor (int id)
在 API 23 中被弃用。现在使用 getColor(int, android.content.res.Resources.Theme)
代替。
查看此以了解更多信息:
https://developer.android.com/reference/android/content/res/Resources
这是一个简单的代码,错误消息没有说明弃用用法的确切位置。
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;
}
}
}
}
正如代码所说,我正在返回可绘制对象或颜色。这很简单。需要更改的警告在哪里,如何跳过此警告,继续返回可绘制对象和颜色?
在 Android API 22 getResources().getDrawable()
中已弃用。现在你应该使用这个方法 getDrawable (int id, Resources.Theme theme)
并且 getColor (int id)
在 API 23 中被弃用。现在使用 getColor(int, android.content.res.Resources.Theme)
代替。
查看此以了解更多信息: https://developer.android.com/reference/android/content/res/Resources