如何在ImageSpan
中使用来自xml矢量图的Drawable
? 我使用了以下两种方法。 但是我的图标没有显示出来。 当我使用来自drawable资源的png时,图标会显示出来。 有什么想法吗?
private void setupEmptyListInfoBox() {
Drawable icon = loadVectorFromResources(getActivity(), R.drawable.ic_add_circle_24dp);
ImageSpan is = new ImageSpan(icon, DynamicDrawableSpan.ALIGN_BASELINE);
String info = getString(R.string.empty_weight_list_info);
int iconPosition = info.indexOf("|");
SpannableString text = new SpannableString(info);
text.setSpan(is, iconPosition, iconPosition + 1, 0);
mEmptyListInfo.setText(text);
}
public static Drawable loadVectorFromResources(Context context, int resId) {
Drawable drawable;
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = VectorDrawableCompat.create(context.getResources(), resId, context.getTheme());
} else {
drawable = context.getResources().getDrawable(resId, context.getTheme());
}
return drawable;
}