protected Activity getActivityForImageView(ImageView imageView) throws MessageException {
Object context = imageView.getContext();
Activity activity = null;
// for activity
if (context instanceof Activity) {
activity = (Activity) imageView.getContext();
}
// for dialog
else if (context instanceof ContextThemeWrapper) {
activity = (Activity) ((ContextThemeWrapper) context).getBaseContext();
}
// otherwise
else {
throw new MessageException(
"your ImageView does not have an activity context, so cannot set bitmap for it. Make sure pass an activity to function View.inflat()");
}
return activity;
}
从ImageView获取关联的Activity
最新推荐文章于 2022-01-11 14:33:40 发布