简体   繁体   English

顶部和底部的Android Alert对话框黑条

[英]Android Alert Dialog black bar on top and bottom

I have the problem that always displays the frame of dialog on my alert dialog. 我遇到的问题是始终在警报对话框上显示对话框的框架。 I don't want to have a black bar on top and bottom. 我不想在顶部和底部有一个黑条。

Can you help me??? 你能帮助我吗???

private void popupDialog(){
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = (LayoutInflater) Quiz1.this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View dialogview = inflater.inflate(R.layout.popup_main, null);
    builder.setView(dialogview);
    closeBtn = (ImageButton) dialogview.findViewById(R.id.Rahmen);

    final AlertDialog popupDia =builder.create();
    popupDia.setCanceledOnTouchOutside(true);
    popupDia.setCancelable(true);

    popupDia.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            popupDia.dismiss();
        }
    });

    closeBtn .setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popupDia.dismiss();
        }
    });
    popupDia.show();
}

如果您不希望使用黑条,只需从清单更改应用程序的主题,使用浅色而不是深色,希望它就是您想要的,即可更改对话框的颜色。

Thank you but I have found the answer here can you see it. 谢谢,但是我找到了答案,在这里可以看到。

AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = (LayoutInflater) this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View dialogview = inflater.inflate(R.layout.popup_main, null);
    ImageButton close = (ImageButton) dialogview.findViewById(R.id.Rahmen);
    final AlertDialog popupDia =builder.create();
    popupDia.setView(dialogview, 0, 0, 0, 0);
    popupDia.setCanceledOnTouchOutside(true);
    popupDia.setCancelable(true);
    popupDia.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            popupDia.dismiss();
        }
    });
    close .setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popupDia.dismiss();
        }
    });
    popupDia.show();

the setView must be seted after the buildig, thats it setView必须在buildig之后设置,就这样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM