2014-03-19 119 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