android - 如何在 android 的 AlertDialog 中包含自定义标题 View ?

标签 android android-alertdialog custom-titlebar

如何在 alertDialog 中包含自定义标题栏?我知道 android sdk 提供 setCustomTitle 方法,但它不起作用

编辑:

    AlertDialog alert = new AlertDialog.Builder(this).setTitle("Test").setMessage("hello").show();
    View view=alert.getLayoutInflater().inflate(R.layout.titlebar, null);
    alert.setCustomTitle(view);

但上面的代码不起作用

注意: 我不是在寻找自定义对话框,而只想自定义其标题布局。如下所示 like this with close Button

最佳答案

您不应该在第一行使用 .show 方法,使用以下代码即可:

AlertDialog.Builder alert = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.titlebar, null);
alert.setCustomTitle(view);
alert.setMessage("helo");
alert.show();

关于android - 如何在 android 的 AlertDialog 中包含自定义标题 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9430233/

相关文章:

Java - 将值添加到二维数组以及如何查看数组?

android - 如何在 Android 的自定义启动器中创建应用程序快捷方式?

android - 让图像通过 AlertDialog 时出现问题

Android:为什么 ContentView.getTop() 中存在差异取决于 FEATURE_NO_TITLE?

android - 使用 ActionBar 添加自定义标题栏

Android通知小图标背景一直是黑色

android - 限制 Android 设备 Wifi 连接

Android:为什么onTouchListener() 会打开多个Alert Dialog?

java - 下面带有滚动和编辑文本的弹出菜单

android - 设置 Activity 的标题栏名称