我将drawables
列表存储为sharedPreferences
作为字符串。
它们存储如下:
android.graphics.drawable.BitmapDrawable@269d6f8
android.graphics.drawable.BitmapDrawable@1c71e5b
现在我想将它们转换回Drawable,以便我可以使用它们。 任何想法?
代码
SharedPreferences.Editor editor=sharedpreferences.edit();
editor.putString(s.getName(),(s.getLogo().toString()));
editor.commit();
我的服务定义为:
public Service(String name, Drawable logo) {
this.name = name;
this.logo=logo;
}
我试图这样做,但它不起作用
String logo=entry.getValue().toString();
//convert string to drawable
byte [] encodeByte=Base64.decode(logo, Base64.DEFAULT);
Bitmap bitmap= BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
Drawable d = new BitmapDrawable(bitmap);