【问题标题】:How to remove border in custom AlertDialog?如何在自定义 AlertDialog 中删除边框?
【发布时间】:2012-08-02 21:46:22
【问题描述】:

我正在尝试使用图像文本和按钮创建自定义 AlertDialog。当我显示它时,我得到一个看起来很可怕的白色边框。

我怎样才能去掉那个白色边框?

这是我的自定义对话框:

public LinearLayout customeLL;
    public void  alertD()
    {
        AlertDialog ad;
        AlertDialog.Builder  builder;
        Context mContext = getApplicationContext();
        TextView a = new TextView(getApplicationContext());
        a.setText("Test dialog");
        ImageView img = new ImageView(getApplicationContext());
        img.setBackgroundResource(R.drawable.bottombar_bg);
        LinearLayout customeLL = new LinearLayout(getApplicationContext());
        customeLL.setOrientation(LinearLayout.VERTICAL);
        customeLL.addView(img,curWidth,37);
        customeLL.addView(a,curWidth,37);
        builder = new AlertDialog.Builder(myClass.this);
        builder.setView(customeLL);
        ad=builder.create();
        ad.show();

    }

如您所见,topborder 和图像有 2-3 px 的空间。

【问题讨论】:

  • 白钻是什么意思?
  • 只是一个边框。 alertDialog 中的边框(默认为白色边框)
  • 你可以用Dialog代替Alert..?
  • 当然,如果我可以删除文件夹:(。但所有人都说我必须在 alertdialog 中创建自定义。(用于图像而不是标题)。我想要垂直样式:图像(而不是标题) , text1,text2,text3,btn1,btn2 ....
  • 你可以在对话框中添加任何你想要的布局..

标签: android android-alertdialog


【解决方案1】:

尝试使用 Dialog 而不是 AlertDialog.Builder

.. 用于从对话框中删除边框线..

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

【讨论】:

  • 谢谢,但它只删除标题。我需要删除边框 :(( 请在图片上查看顶部白线 - 可以删除 ?????
  • 我刚刚发布了一个要点,显示了一个带有自定义主题的浮动对话框,没有标题或边框:gist.github.com/2643546
【解决方案2】:

这将删除边框:

AlertDialog ad;
ad= new AlertDialog.Builder(context).create();
ad.show();
ad.setContentView(R.layout.dialog_layout); // set your custom layout

// Then initialize your dialog views like this
TextView txt= (TextView) ad.findViewById(R.id.dialog_text); // a TextView inside dialog 
                                                            // layout
txt.setText("I'm a custom dialog!");

另外,我在全屏模式下使用自定义对话框时遇到了问题。只要对话框没有关闭,我手机的通知栏就会一直显示。使用自定义的 AlertDialog,这将不是问题 ;)

【讨论】:

    【解决方案3】:

    如果您希望对话框边框以任何颜色显示,您必须使用布局样式和主题。这里有一篇很棒的文章:http://blog.androgames.net/10/custom-android-dialog/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多