android - 是否可以替换 AlertDialog 布局?
问题描述
我一直在尝试创建一个自定义的 AlertDialog 并且我知道我可以用来AlertDialog.Builder.setView()
在对话框中放置一个自定义视图,但是是否可以完全替换默认布局?
编辑:我想这样做是因为它允许我使用带有自定义布局的构建setMessage()
器等setTitle()
解决方案
可以自定义或完全更改,Dialog
或者AlertDialog
,您可以Dialog
像这样自定义
private void customDialog() {
final Dialog dialog = new Dialog(ActivityUserVideoPlay.this, R.style.MaterialDialogSheet);
dialog.setContentView(R.layout.your_layout_foor_dialog); // your custom view.
dialog.setCancelable(false);
dialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
dialog.show();
}
这是对话框的样式
<style name="MaterialDialogSheet" parent="@android:style/Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>
</style>
使用动画根据需要打开或关闭对话框,否则可以将其删除。
希望能帮助到你。
推荐阅读
- python - 从分隔符拆分二进制数据
- git - 将给定分支上的提交重置为作者的信息(电子邮件、日期等)
- python - 如何对自定义上下文管理器进行单元测试?
- python - 如何将一列中的熊猫多个值组合到另一列
- python-3.x - 多任务处理@Raspi?在流式传输音频时运行 python 脚本
- reactjs - 使用第二个参数时如何防止在组件安装时反应 useEffect 运行
- python - 如何通过 django-microsoft-auth 在 Django 中使用 Azure AD 进行身份验证
- c - 链表返回单链表 C 中的根节点
- sql-server - 消息 16916,级别 16,状态 1,第 52 行名称为“depozit”的游标不存在
- python - 谷歌存储上 bucket() 和 get_bucket() 的区别