gpt4 book ai didi

安卓:自定义AlertDialog

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:21:57 26 4
gpt4 key购买 nike

我通过以下代码创建了一个自定义警报对话框:

AlertDialog.Builder builder;
AlertDialog alertDialog;

LayoutInflater inflater = (LayoutInflater)ActivityName.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_layout,(ViewGroup)findViewById(R.id.layout_root));

builder = new AlertDialog.Builder(getParent());
builder.setView(layout);
alertDialog = builder.create();
alertDialog.show();

问题是弹出窗口被默认的对话框背景所包围,该背景具有自己的标题空白空间(因为未设置标题)。我该如何删除它。我试过通过 ContextThemeWrapper 来设置自定义样式builder = new AlertDialog.Builder(new ContextThemeWrapper(getParent(), R.style.CustomDialogTheme));

但是它不起作用。我怎么做?!!!提前致谢。自定义样式xml如下:

<style name="CustomDialogTheme" parent="android:style/Theme.Dialog.Alert">
<item name="android:windowIsFloating">false</item>
<item name="android:windowNoTitle">true</item>
</style>

This is the output on the emulator

最佳答案

使用跟随

Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);

展开布局并将 View 设置为对话框的内容

dialog.setContentView(view);

关于安卓:自定义AlertDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8952745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com