有没有办法使自定义对话框的标题部分不可见?

发布于 2024-09-28 11:50:49 字数 841 浏览 9 评论 0原文

只是一个简单的问题,不知道如何做。有谁知道如何/是否可以做到这一点?

原因:我只想要一个没有分区的实体对话框,因为它在我的应用程序中看起来更好一点。

编辑

public void showCustomDialog() {
    Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.customdialog);

    TextView thisText = (TextView) dialog.findViewById(R.id.customDialogThisText);
    thisText.setText("This");
    TextView thatText = (TextView) dialog.findViewById(R.id.customDialogThatText);
    thatText.setText("That");
    ImageView image = (ImageView) dialog.findViewById(R.id.customDialogImageView);
    image.setImageResource(R.drawable.icon);

    //Crashes the program with an AndroidRuntimeError
    //dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);

    dialog.show();
}

Just a simple problem without any idea of how to do it. Does anyone know how/if this can be done?

Reason: I just want one solid dialog box with no partitions as it looks a little better in my application.

EDIT

public void showCustomDialog() {
    Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.customdialog);

    TextView thisText = (TextView) dialog.findViewById(R.id.customDialogThisText);
    thisText.setText("This");
    TextView thatText = (TextView) dialog.findViewById(R.id.customDialogThatText);
    thatText.setText("That");
    ImageView image = (ImageView) dialog.findViewById(R.id.customDialogImageView);
    image.setImageResource(R.drawable.icon);

    //Crashes the program with an AndroidRuntimeError
    //dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);

    dialog.show();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狼性发作 2024-10-05 11:50:49

只要不调用 setTitle() 就不会出现标题,如下所示:

alt text

LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
new AlertDialog.Builder(AlertDialogSamples.this)
    .setView(textEntryView)
    .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            /* User clicked OK so do some stuff */
        }
    })
    .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            /* User clicked cancel so do some stuff */
        }
    })
    .create();

Just don't call setTitle() and there will be no title, like that:

alt text

LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
new AlertDialog.Builder(AlertDialogSamples.this)
    .setView(textEntryView)
    .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            /* User clicked OK so do some stuff */
        }
    })
    .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

            /* User clicked cancel so do some stuff */
        }
    })
    .create();
抱着落日 2024-10-05 11:50:49

只需致电
dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
在设置对话框的视图之前
dialog.setContentView(R.layout.customdialog);

Just call
dialog.requestWindowFeature(dialog.getWindow().FEATURE_NO_TITLE);
before setting the view of the dialog by
dialog.setContentView(R.layout.customdialog);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文