コード例 #1
0
 public CustomDialog(Context context, DialogBuilder builder)
     : base(context, Android.Resource.Style.ThemeTranslucentNoTitleBar)
 {
     // Dialog 배경을 투명 처리 해준다.
     this.builder = builder;
 }
コード例 #2
0
        private void InitView(Context context, IAttributeSet attrs)
        {
            LayoutInflater inflater = LayoutInflater.From(context);
            View           layout   = inflater.Inflate(Resource.Layout.view_spinner, this, false);

            AddView(layout);

            if (attrs != null)
            {
                TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.KakaoDialogSpinner);
                title            = a.GetString(Resource.Styleable.KakaoDialogSpinner_kakao_prompt);
                iconResId        = a.GetResourceId(Resource.Styleable.KakaoDialogSpinner_kakao_icon, 0);
                titleBgResId     = a.GetResourceId(Resource.Styleable.KakaoDialogSpinner_kakao_dialogTitle, 0);
                titleTextColor   = a.GetResourceId(Resource.Styleable.KakaoDialogSpinner_kakao_titleTextColor, 0);
                showTitleDivider = a.GetBoolean(Resource.Styleable.KakaoDialogSpinner_kakao_showTitleDivider, false);

                int entriesResId = a.GetResourceId(Resource.Styleable.KakaoDialogSpinner_kakao_entries, 0);
                if (entriesResId > 0)
                {
                    entryList = new List <string>(Resources.GetStringArray(entriesResId));
                }

                a.Recycle();
            }

            ImageView icon = layout.FindViewById <ImageView>(Resource.Id.menu_icon);

            if (iconResId > 0)
            {
                icon.Visibility = ViewStates.Visible;
                icon.SetBackgroundResource(iconResId);
            }
            else
            {
                icon.Visibility = ViewStates.Gone;
            }

            spinner = layout.FindViewById <TextView>(Resource.Id.menu_title);
            if (entryList != null && entryList.Count > 0)
            {
                spinner.Text = entryList[0];
            }

            DialogBuilder builder = new DialogBuilder(context);

            if (title != null)
            {
                builder = builder.SetTitle(title);
            }

            builder.SetTitleBgResId(titleBgResId);
            builder.SetTitleTextColor(titleTextColor);
            builder.SetShowTitleDivider(showTitleDivider);

            if (entryList != null)
            {
                listView = (ListView)inflater.Inflate(Resource.Layout.view_custom_list, null, false);
                builder.SetView(listView);
                dialog = builder.Create();

                adapter = new KakaoSpinnerAdapter(new KakaoSpinnerItems(iconResId, entryList), new MySpinnerListener((adapter, position) =>
                {
                    spinner.Text = entryList[position];
                    if (dialog != null)
                    {
                        dialog.Dismiss();
                    }

                    if (listener != null)
                    {
                        listener.OnItemSelected(adapter, position);
                    }
                }));
                listView.SetAdapter(adapter);
            }

            this.Click += (s, e) =>
            {
                ShowDialog();
            };
        }