2014-03-19 115 views
0

我有一个对话框,里面有一些TextViews和ImageViews。现在我想与Share Intent分享。这可能吗?我可以共享一个对话框或将其首先转换为位图并共享它吗?Android,Java:共享对话框

+0

是的,它是可能的。但是,你想分享你的对话形象? – Piyush

+0

是的,我有一个对话框,并希望分享它像一个截图。 – L3n95

+0

是的,你必须先将它转换为位图,然后分享它 – Piyush

回答

1

您可以使用此方法。

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; 
} 

OR 简单地使用它。

View v1 = view.getRootView(); 
v1.setDrawingCacheEnabled(true); 
Bitmap bm = v1.getDrawingCache(); 
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm); 

UPDATE:

,如果你不想使用,然后用这个。

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")); 
+0

而视图v1是对话框? – L3n95

+0

v1是View和view.getRootView()的对象;是对话框或活动的父级布局的父级布局视图。 – Piyush

+0

BitmapDrawable已被弃用是否有必要获取它在BitmapDrawable中的位图不够? – L3n95

0

使用活动上下文分别创建自定义对话框并在单独的活动中使用它。

+0

我有一个自定义对话框类,那么该怎么做? – L3n95

+0

使用此链接。 http://stackoverflow.com/questions/7535398/how-to-implement-a-dialog-for-different-activities – Shriram