2016-12-26 73 views
2

我想知道如何更改我的AlertDialog的设计,按钮的背景。更改AlertDialog的背景

谢谢。

new AlertDialog.Builder(this) 
       .setTitle("Exit") 
       .setMessage("Do you want to exit") 
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
          finish(); 
        } 
       }) 
       .setNegativeButton("No", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
         // do nothing 
        } 
       }) 
       .setIcon(android.R.drawable.ic_menu_zoom) 
       .show(); 
    } 
+0

你可以描述更多您的问题@DesignMan。 –

+0

您可以使用所需的设计创建布局,并在警报对话框中设置相同的布局。 –

+0

是的,但我怎么能让它像AlertDialog,我的意思是我怎么可以定义我的新布局的高和宽度! – DesignMan

回答

0
AlertDialog.Builder alertDialog_ImageSelector=new AlertDialog.Builder(mcontext); 
        View imageGuideLineInfo=getActivity().getLayoutInflater().inflate(R.layout.your_alyout,null); 
        alertDialog_ImageSelector.setView(imageGuideLineInfo); 
        TextView tv_guidelines=(TextView)imageGuideLineInfo.findViewById(R.id.tv_guidelines); 
        final AlertDialog adinfo=alertDialog_ImageSelector.create(); 
        adinfo.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//here you can change the background of alertDialog. 
        adinfo.show(); 
如果要更改按钮的背景

,那么你需要创建your_view.xml按钮和这里的setBackground约束力。

+0

的常用代码,可以解释更多的按钮;请。 – DesignMan

+0

这些按钮您必须在您的布局中创建它们并将它们绑定到此处。看看我为TextView做了什么。现在我可以将TextView的背景设置为tv.setBackgroundColor(Color.RED);在您的情况下,它应该是Button –

+0

非常感谢@Rushi Ayyappa! – DesignMan

0

使用这个机器人内置的主题

AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);