Android实现半透明的AlertDialog

    xiaoxiao2021-03-25  114

    运行效果:

    实现代码:

    public void clickDialog(View v){ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("这是一个提示的标题"); builder.setMessage("我是一个内容"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Toast.makeText(MainActivity.this,"确定",Toast.LENGTH_SHORT).show(); } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Toast.makeText(MainActivity.this,"取消",Toast.LENGTH_SHORT).show(); } }); builder.setNeutralButton("忽略", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Toast.makeText(MainActivity.this,"忽略",Toast.LENGTH_SHORT).show(); } }); AlertDialog alertDialog = builder.create(); //实现提示窗体透明的代码 Window window = alertDialog.getWindow(); WindowManager.LayoutParams attributes = window.getAttributes() attributes.alpha = 0.6f; window.setAttributes(attributes); alertDialog.show(); }
    转载请注明原文地址: https://ju.6miu.com/read-18483.html

    最新回复(0)