就是长按桌面,弹出的"Add to Home screen"对话框,里面是个带图标的列表,请问这对话框怎么去实现?

解决方案 »

  1.   

    经过研究找到了实现方法,现共享给大家一、首先要创建一个对话框:        private AddAdapter mAdapter;        Dialog createDialog() {
                mWaitingForResult = true;            mAdapter = new AddAdapter(Launcher.this);            final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
                builder.setTitle(getString(R.string.menu_item_add_item));            // 设置列表的Adapter
                builder.setAdapter(mAdapter, this);            builder.setInverseBackgroundForced(true);
                AlertDialog dialog = builder.create();
                dialog.setOnCancelListener(this);
                return dialog;
            }
    二、实现Adapterpublic class AddAdapter extends BaseAdapter {    private final LayoutInflater mInflater;
       
        private final ArrayList<ListItem> mItems = new ArrayList<ListItem>();
       
        public static final int ITEM_SHORTCUT = 0;
       
        /**
         * Specific item in our list.
         */
        public class ListItem {
            public final CharSequence text;
            public final Drawable image;
            public final int actionTag;
           
            public ListItem(Resources res, int textResourceId, int imageResourceId, int actionTag) {
                text = res.getString(textResourceId);
                if (imageResourceId != -1) {
                    image = res.getDrawable(imageResourceId);
                } else {
                    image = null;
                }
                this.actionTag = actionTag;
            }
        }
       
        public AddAdapter(Launcher launcher) {
            super();        mInflater = (LayoutInflater) launcher.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           
            // Create default actions
            Resources res = launcher.getResources();
           
            mItems.add(new ListItem(res, R.string.group_shortcuts,
                    R.drawable.ic_launcher_shortcut, ITEM_SHORTCUT));
        }    public View getView(int position, View convertView, ViewGroup parent) {
            ListItem item = (ListItem) getItem(position);
           
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.add_list_item, parent, false);
            }
           
            TextView textView = (TextView) convertView;
            textView.setTag(item);
            textView.setText(item.text);
            textView.setCompoundDrawablesWithIntrinsicBounds(item.image, null, null, null);
           
            return convertView;
        }    public int getCount() {
            return mItems.size();
        }    public Object getItem(int position) {
            return mItems.get(position);
        }    public long getItemId(int position) {
            return position;
        }
    }三、每一个列表项是一个TextView,其Layout如下: <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:textAppearance="?android:attr/textAppearanceLargeInverse"
    android:gravity="center_vertical"
    android:drawablePadding="14dip"
    android:paddingLeft="15dip"
    android:paddingRight="15dip" />这样就创建出跟系统一样的图片列表对话框了
      

  2.   

    你长按下在activity中让它出来怎么实现的。