Android 自定義分享列表ACTION_SEND
阿新 • • 發佈:2019-02-16
注:ShareCustomAdapter自己建一個就行了。(有一個圖示和一個分享的名)private void initSharePopupWindow(View parent) { PopupWindow sharePopupWindow = null; View view = null; ListView shareList = null; if(null == sharePopupWindow) { //載入佈局檔案 view = LayoutInflater.from(DetailExchangeActivity.this).inflate(R.layout.popup_share, null); shareList = (ListView) view.findViewById(R.id.share_list); List<AppInfo> shareAppInfos = getShareAppList(); final ShareCustomAdapter adapter = new ShareCustomAdapter(mContext, shareAppInfos); shareList.setAdapter(adapter); shareList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub Intent shareIntent = new Intent(Intent.ACTION_SEND); AppInfo appInfo = (AppInfo) adapter.getItem(position); shareIntent.setComponent(new ComponentName(appInfo.getAppPkgName(), appInfo.getAppLauncherClassName())); shareIntent.setType("text/plain"); // shareIntent.setType("*/*"); //這裡就是組織內容了, shareIntent.putExtra(Intent.EXTRA_TEXT, "測試,這裡傳送推廣地址"); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); DetailExchangeActivity.this.startActivity(shareIntent); } }); sharePopupWindow = new PopupWindow(view, (int)(160 * density), LinearLayout.LayoutParams.WRAP_CONTENT); } //使其聚焦 sharePopupWindow.setFocusable(true); //設定允許在外點選消失 sharePopupWindow.setOutsideTouchable(true); // 這個是為了點選“返回Back”也能使其消失,並且並不會影響你的背景 sharePopupWindow.setBackgroundDrawable(new BitmapDrawable()); //xoff,yoff基於anchor的左下角進行偏移。正數表示下方右邊,負數表示(上方左邊) //showAsDropDown(parent, xPos, yPos); sharePopupWindow.showAsDropDown(parent, -5, 5); }