[英]Android, Java: Share a dialog
我有一个对话框,里面有一些TextViews和ImageViews。 现在,我想与共享意图共享此内容。 这可能吗? 我可以共享一个对话框,还是先将其转换为位图,然后共享?
您可以使用此方法。
public static Bitmap TakeBitmapFromDialog(View v, int width, int height) {
Bitmap b = Bitmap.createBitmap(width , height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
return b;
}
或简单地使用它。
View v1 = view.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
更新:
如果您不想使用它,请使用它。
Bitmap cs = null;
view.setDrawingCacheEnabled(true);
view.buildDrawingCache(true);
cs = Bitmap.createBitmap(view.getDrawingCache());
Canvas canvas = new Canvas(cs);
view.draw(canvas);
canvas.save();
view.setDrawingCacheEnabled(false);
如果您要共享该位图,则需要插入媒体图片,例如,
String path = Images.Media.insertImage(getContentResolver(), cs,
"MyImage", null);
Uri file = Uri.parse(path);
现在分享
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, file);
startActivity(Intent.createChooser(sharingIntent,
"Share image using"));
使用活动上下文分别创建一个自定义对话框,并在单独的活动中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.