直接上代码:
样式:
<style name="BottomDialog" parent="AlertDialog.AppCompat"> <item name="android:windowIsFloating">true</item> <item name="android:windowFrame">@null</item> <item name="android:windowNoTitle">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:backgroundDimEnabled">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:fullBright">@color/clear</item> <item name="android:fullDark">@color/clear</item> <item name="android:topBright">@color/clear</item> <item name="android:topDark">@color/clear</item> <item name="android:borderlessButtonStyle">@color/clear</item> </style>
,
//自定义dialog,自定义重命名dialog public void showRenameDialog() { // AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // // 布局填充器 // LayoutInflater inflater = LayoutInflater.from(getActivity()); // View view = inflater.inflate(R.layout.user_name_dialog, null); // // 设置自定义的对话框界面 // builder.setView(view); // // cus_dialog = builder.create(); // cus_dialog.show(); View view = LayoutInflater.from(context).inflate(R.layout.editscene_dialog, null); TextView confirm; //确定按钮 TextView cancel; //确定按钮 TextView tv_title; // final TextView content; //内容 cancel = (TextView) view.findViewById(R.id.call_cancel); confirm = (TextView) view.findViewById(R.id.call_confirm); tv_title = (TextView) view.findViewById(R.id.tv_title); // tv_title.setText("是否拨打119"); // content.setText(message); //显示数据 final Dialog dialog = new Dialog(context, R.style.BottomDialog); dialog.setContentView(view); dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); DisplayMetrics dm = context.getResources().getDisplayMetrics(); int displayWidth = dm.widthPixels; int displayHeight = dm.heightPixels; android.view.WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); //获取对话框当前的参数值 p.width = (int) (displayWidth * 0.8); //宽度设置为屏幕的0.5 // p.height = (int) (displayHeight * 0.5); //宽度设置为屏幕的0.5 // dialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失 dialog.getWindow().setAttributes(p); //设置生效 dialog.show(); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); }