有沒有一種方法可以自定義分享意圖的佈局?默認情況下是ListView,如果客戶端要求所有內容相同,但是顯示網格視圖,該怎麼辦!我知道如何使用packageManager過濾所需的應用程序。但我想將ListView更改爲與其他所有內容相同的gridView。分享意圖:自定義佈局
1
A
回答
2
可以撥打下面的對話框按您的要求:
private void showAlertDialog() {
PackageManager pm = getPackageManager();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
GridView gridView = new GridView(this);
email.putExtra(Intent.EXTRA_EMAIL,
new String[] { "[email protected]" });
email.putExtra(Intent.EXTRA_SUBJECT, "Hi");
email.putExtra(Intent.EXTRA_TEXT, "Hi,This is Test");
email.setType("text/plain");
List<ResolveInfo> launchables = pm.queryIntentActivities(email, 0);
Collections
.sort(launchables, new ResolveInfo.DisplayNameComparator(pm));
adapter = new AppAdapter(pm, launchables);
gridView.setNumColumns(3);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
ResolveInfo launchable = adapter.getItem(position);
ActivityInfo activity = launchable.activityInfo;
ComponentName name = new ComponentName(
activity.applicationInfo.packageName, activity.name);
email.addCategory(Intent.CATEGORY_LAUNCHER);
email.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
email.setComponent(name);
startActivity(email);
}
});
builder.setView(gridView);
builder.setTitle("Share");
builder.show();
}
row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp" >
<ImageView
android:id="@+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:paddingBottom="2dp"
android:paddingLeft="2dp"
android:paddingRight="5dp"
android:paddingTop="2dp" />
<TextView
android:id="@+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/icon"
android:gravity="center_vertical"
android:paddingBottom="2sp"
android:paddingTop="4sp"
android:textColor="@android:color/white"
android:textSize="11pt" />
</LinearLayout>
適配器類:
class AppAdapter extends ArrayAdapter<ResolveInfo> {
private PackageManager pm = null;
AppAdapter(Context context, PackageManager pm, List<ResolveInfo> apps) {
super(context, R.layout.row, apps);
this.pm = pm;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = newView(parent);
}
bindView(position, convertView);
return (convertView);
}
private View newView(ViewGroup parent) {
return (getLayoutInflater().inflate(R.layout.row, parent, false));
}
private void bindView(int position, View row) {
TextView label = (TextView) row.findViewById(R.id.label);
label.setText(getItem(position).loadLabel(pm));
ImageView icon = (ImageView) row.findViewById(R.id.icon);
icon.setImageDrawable(getItem(position).loadIcon(pm));
}
}
1
我不認爲你可以開箱即用。所以你需要用網格創建你自己的共享對話框。 這裏是一些例子https://github.com/xinanadu/CustomShare/blob/master/app/src/main/java/info/zhegui/share/MainActivity.java
相關問題
- 1. 自定義分享意圖Android
- 2. 自定義圖案佈局
- 3. 自定義分享意向活動
- 4. 自定義佈局
- 5. 使用自定義模板自定義Pagerfanta分頁的佈局
- 6. octoberCMS |分享佈局
- 7. 自定義地圖的佈局
- 8. 自定義視圖的Android佈局
- 9. Android佈局與自定義視圖
- 10. 自定義列表視圖項佈局
- 11. 佈局與自定義視圖
- 12. xml佈局中的自定義視圖
- 13. 自定義UITableViewCell子視圖佈局
- 14. 自定義視圖搞亂佈局
- 15. 自定義視圖或虛擬佈局?
- 16. 自定義視圖的佈局幫助
- 17. 自定義佈局的餅圖
- 18. Android的地圖自定義佈局
- 19. 獲取視圖的自定義佈局
- 20. Android自定義列表視圖佈局到另一個佈局
- 21. 試圖自定義Facebook分享按鈕
- 22. Android自定義佈局(sneekbar)
- 23. 自定義佈局ActionBarSherlock
- 24. 自定義抽屜佈局
- 25. 自定義Android佈局
- 26. ContextMenuStrip自定義佈局
- 27. Log4j2自定義佈局
- 28. iPhone UITableViewController自定義佈局
- 29. BlackBerry - 自定義佈局
- 30. ListActivity佈局自定義
你想顯示僅應用程序圖標gridview或圖標的名字? – Riser 2014-12-02 10:04:41
名稱的應用程序。 – Prachi 2014-12-02 10:08:28