java - 如何在android studio中圆角对话框
问题描述
刚开始学习android开发,想做一个好看的对话框。
我尝试查找它,其中大多数都告诉我制作一个新形状并将其添加为对话框背景,但我似乎不明白如何将新形状设置为背景。
这是我的对话框代码:
new AlertDialog.Builder(this)
.setTitle(" ")
.setMessage("Congrats! Player " + winner +" wins!")
.setPositiveButton("Play again", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
//my code here
}
})
.setNegativeButton("F", null)
.show();
如何将我的形状背景 xml 链接到此对话框以及如何使正按钮具有屏幕截图中的背景?
编辑:问题已编辑,因为我已经尝试过下面的方法我似乎不理解它,除了它有多个部分(页眉,页脚),我真的不需要我的要求更基本。
解决方案
您可以轻松地为您的对话设置自定义AlertDialog
视图setView(View view)
。
您的代码将是这样的:
View view = inflater.inflate(R.layout.your_layout_name, null);
new AlertDialog.Builder(this)
.setView(view)
.create()
.show();
推荐阅读
- vue.js - 从多个下拉列表中过滤掉选定的选项
- json - Julia 中的 API POST 请求
- reactjs - React - 获取数据并存储在变量中
- ansible - Ansible:如果以前的任务导致更改==true,则重新加载容器?
- html - 还有另一种设置背景图像的方法吗?
- google-ads-api - Google Ads 中出现“无法抓取目标”错误,其他广告正在运行
- apache-kafka - Apache Kafka:如何正确配置消息缓冲
- javascript - Webpack 在构建的 html 文件中添加“auto/”到脚本标签
- javascript - 我想存储来自用户的输入,以便可以根据要求将其取回
- javascript - onClick() 仅适用于第一次点击 - React