How to add title to the custom Dialog?

后端 未结 7 702
猫巷女王i
猫巷女王i 2021-01-12 20:37

How can i add title to this custom dialog??

\"enter

I have tried like this

7条回答
  •  不要未来只要你来
    2021-01-12 21:30

    Why not use an AlertDialog if you have 3 or less buttons?

    My AlertDialog looks like this:

    enter image description here

    My java code:

    LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.add_filter, null);
    
    AlertDialog alertDialog = new AlertDialog.Builder(this)
            .create();
    alertDialog.setTitle("AlertDialog title");
    alertDialog.setMessage("AlertDialog message");
    alertDialog.setView(view);
    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                        int which) {
                    dialog.dismiss();
                }
            });
    alertDialog.show();
    

    My XML:

    
    
    
        
    
    
    

    Simple yet does what you need.

提交回复
热议问题