我想用自己的图片定义AlertDialog.Builder的按钮,比如下面的取消按钮的背景图片,用什么实现啊。谢谢new AlertDialog.Builder(ICU_login.this)
.setTitle("标题")
.setMessage("自定义按钮")
.setNegativeButton("取消", null)
.show();

解决方案 »

  1.   

    要实现这个功能的话,只有自定义AlertDialog的布局了,然后用builder.setView()放上去,系统的按钮是不能改的
      

  2.   

    使用builder.setView(View view)的话,就是按照自己喜欢的方式布局了,就是一个布局文件,系统的东西,诸如标题、内容、按钮全部不用设置
      

  3.   

    - -||你把标题放在view中啊,setTitle("标题")
    .setMessage("自定义按钮")
    .setNegativeButton("取消", null)
    这些都不要,只要一个setView(View view),view的布局,你照着系统弹出框来写
      

  4.   

    帮我改一下,怎么失效了。布局AlertDialog.Builder builder = new AlertDialog.Builder(this).setMessage("我是内容").setNegativeButton("取消", null);
    TextView title = new TextView(this);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    title.setText("标题");
    title.setLayoutParams(params);
    builder.setCustomTitle(title);
    builder.show();
      

  5.   


    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    TextView title = new TextView(this);    
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
                    params.gravity = Gravity.CENTER;
                    title.setText("标题");
                    title.setLayoutParams(params);
                    builder.setView(title);
                    builder.show();你现在的布局只是一个textview,也就是说只有标题,内容、按钮这些你都没有指定,所以最好是将TextView title 换成一个布局,可以在代码中定义,也可以用xml配置,然后builder.setView(view);
    放到里面去
      

  6.   

    你的textview可以引用一个外部的布局文件,至于想要他按什么对齐,在布局文件里改即可。