java - 带有圆角的Android对话框 - 仍然显示没有角半径的背景
问题描述
我想制作圆角对话框;但是在我完成后,它看起来像这样>>
爪哇
AlertDialog.Builder dialogBuilder= new AlertDialog.Builder(this);
dialogBuilder.setView(R.layout.complain_dialog);
final AlertDialog alertDialog= dialogBuilder.create();
alertDialog.show();
XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="100dp"
app:cardBackgroundColor="#FFF"
app:cardCornerRadius="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="15dp"
android:background="@color/black_overlay" />
</android.support.v7.widget.CardView>
问题是:为什么对话框仍然显示在没有角半径的背景中?
在搜索了这个问题的解决方案后,我找到了其中一些解决方案>>
Java-经过测试上述解决方案
Dialog dialog= new Dialog(getContext());
dialog.setContentView(R.layout.complain_dialog);
dialog.getWindow().setBackgroundDrawable(new
ColorDrawable(Color.TRANSPARENT));
dialog.show();
测试解决方案后的结果
现在对话框根本没有出现!谁能给我解决这个问题的方法?先感谢您。
解决方案
AlertDialog
具有相同布局的解决方案(测试 On Kitkat
)。
AlertDialog.Builder dialogBuilder= new AlertDialog.Builder(this);
dialogBuilder.setView(R.layout.temp);
final AlertDialog alertDialog= dialogBuilder.create();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.show();
要显示Dialog
相同,您需要设置对话框的宽度。这是一个参考。否则它将采用 Content width 。在将内容视图设置为 之前执行所有dialog.getWindow()
操作Dialog
。
推荐阅读
- javascript - 加载 XML、应用 XSL 并附加到现有的 HTML 页面
- r - Rvest mailto 与python - 如何将 python 文件集成到 Django 项目中?
- pandas - 合并熊猫数据框中的列表
- angular - 角度 10 中引导选项卡面板中的逻辑问题
- amazon-web-services - Amazon SES 信誉跳出率重置期
- typescript - 键入一个接受对象及其属性名称的通用函数,期望 obj[propName] 是某种类型,例如 sumBy、mapBy
- javascript - 没有 pg_hba.conf,只是不会工作。我已经找到并尝试更改了很多次
- algorithm - 买卖股票的最佳时机 IV
- formatting - Splunk 仪表板格式问题