Android开发中自定义dialog样式的步骤有哪些?

Android开发中自定义dialog样式的步骤有哪些?

        Android开发中,我们常常会根据产品需要,在Android界面上弹出一些对话框,自定义dialog对话框就是其中比较常用的一种。那在Android开发中,自定义dialog样式的方法和步骤有哪些呢?下面我们就来一起看看吧。

 

  1、自定义Dialog

  final Dialog dialog = new Dialog(this, R.style.Theme_dialog);

 

  2、窗口布局

  View contentView = LayoutInflater.from(this).inflate(R.layout.select_list_dialog, null);

 

  3、把设定好的窗口布局放到dialog

  dialog.setContentView(contentView);

 

  4、设定点击窗口空白处取消会话

  dialog.setCanceledOnTouchOutside(true);

 

  5、具体的操作

  ListView msgView = (ListView) contentView.findViewById(R.id.listview_flow_list);

 

  6、展示窗口

  dialog.show();

 

  例:

        final Dialog dialog = new Dialog(this, R.style.Theme_dialog);

        View contentView = LayoutInflater.from(this).inflate(R.layout.select_list_dialog, null);

        dialog.setContentView(contentView);

        dialog.setCanceledOnTouchOutside(true);

        ListView msgView = (ListView) contentView.findViewById(R.id.listview_flow_list);

 

        TextView titleText = (TextView) contentView.findViewById(R.id.title);

        titleText.setText("请选择Android开发方向");

       

        SelectBankCardDialogAdapter adapter = new SelectBankCardDialogAdapter(this, mBankcardList);

        msgView.setAdapter(adapter);

        msgView.setOnItemClickListener(new OnItemClickListener() {

 

 

            @Override

            public void onItemClick(AdapterView parent, View view, int position, long id) {

                // Toast.makeText(RechargeFlowToMobileActivity.this,

                // position+"", 0).show();

                mSelectCard = mBankcardList.get(position);

                String area = mSelectCard.getBank_card();

                mCardNumberText.setText(area);

                dialog.dismiss();

            }

        });

        Button closeBtn = (Button) contentView.findViewById(R.id.close);

        closeBtn.setClickable(true);

        closeBtn.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View v) {

                dialog.dismiss();

            }

        });

dialog.show();

 

 以上就是Android中自定义dialog样式的详细方法和步骤,你学会了么?如果在Android开发中,大家还有更好的自定义dialog样式的方法,也欢迎分享。

 

你可能感兴趣的:(android,Android开发,dialog)