自定义一个在底部显示的dialog

最近开发软件的时候,需要实现一个在底部显示的dialog,入下图所示:

来看看这个dialog的创建:

	        switch_camera_dialog = new Dialog(getActivity()); 
	        switch_camera_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
	        switch_camera_dialog.setContentView(R.layout.switch_camera_dialog);
	        switch_camera_dialog.setCanceledOnTouchOutside(true);
	        //switch_camera_dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL);

		Window dialogWindow = switch_camera_dialog.getWindow();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		//dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP);
		lp.width = LayoutParams.MATCH_PARENT;
		lp.height = LayoutParams.WRAP_CONTENT;
                lp.gravity = Gravity.BOTTOM;
		dialogWindow.setAttributes(lp);
		//dialogWindow.requestFeature(Window.FEATURE_NO_TITLE);
		dialogWindow.setBackgroundDrawableResource(R.drawable.fingerprint_bg_white);
			
		View_camera_before = (View)switch_camera_dialog.findViewById(R.id.icon_camera_Before);
		View_camera_before.setOnClickListener(new OnClickListener(){
				@Override
				public void onClick(View arg0) {
					selected_san_pai_camera_switch = FingerPrint_Utils.shanpai_pcakage_before;
					//saved = true;
	
					View_camera_before.setSelected(true);
					View_camera_back.setSelected(false);
				}});

		View_camera_back = (View)switch_camera_dialog.findViewById(R.id.icon_camera_Back);
		View_camera_back.setOnClickListener(new OnClickListener(){
				@Override
				public void onClick(View arg0) {
					selected_san_pai_camera_switch = FingerPrint_Utils.shanpai_pcakage_back;
					//saved = true;
					
					View_camera_before.setSelected(false);
					View_camera_back.setSelected(true);
				}});

		if(selected_str != null && selected_str.indexOf(FingerPrint_Utils.shanpai_pcakage_before,0) > -1){
				View_camera_before.setSelected(true);
		}else{
				View_camera_back.setSelected(true);
		}
		Button ok_button = (Button) switch_camera_dialog.findViewById(R.id.button_ok);	//
		ok_button.setBackgroundResource(hwdroid.R.drawable.hw_btn_default);
		ok_button.setOnClickListener(new OnClickListener(){
				@Override
				public void onClick(View arg0) {
					if(selected_san_pai_camera_switch == null){
						selected_san_pai_camera_switch = FingerPrint_Utils.shanpai_pcakage_back;
					}
					if(selected_Preference != null){
						selected_Preference.setChecked(false);
					}
					selected_Preference = SHAN_PAI_Preference;

					selected_str = selected_san_pai_camera_switch;
					SHAN_PAI_Preference.setChecked(true);
					switch_camera_dialog.dismiss();
					selected_san_pai_camera_switch = null;
					saved = true;
				}});

		Button no_button = (Button) switch_camera_dialog.findViewById(R.id.button_cancel);	
		no_button.setBackgroundResource(hwdroid.R.drawable.hw_btn_default);
		no_button.setOnClickListener(new OnClickListener(){
				@Override
				public void onClick(View arg0) {
					selected_san_pai_camera_switch = null;
					if(selected_Preference != null){
						selected_Preference.setChecked(true);
					}
					//SHAN_PAI_Preference.setChecked(false);
					switch_camera_dialog.dismiss();
				}});
		//switch_camera_dialog.setOnDismissListener(this);

其中重点代码:

            switch_camera_dialog.setContentView(R.layout.switch_camera_dialog);

          //.....

            Window dialogWindow = switch_camera_dialog.getWindow();
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            //dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP);
            lp.width = LayoutParams.MATCH_PARENT;
            lp.height = LayoutParams.WRAP_CONTENT;
            lp.gravity = Gravity.BOTTOM;
            dialogWindow.setAttributes(lp);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值