How to create the above custom dialog in android?

前端 未结 2 1787
一生所求
一生所求 2021-01-16 13:58

Can someone tell me how to create the above dialog view similar/exactly to the link [here][1], whereby the focus of the problem is to create the view in the centre of the pi

2条回答
  •  甜味超标
    2021-01-16 14:21

    Try following code

    Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Alert !");
    builder.setMessage("your text here");
    builder.setPositiveButton("Show Video", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
            connect = false;
        }
    });
    builder.setNegativeButton("Show Map", new DialogInterface.OnClickListener()
    {
    
    @Override
    public void onClick(DialogInterface arg0, int arg1)
    {
        // TODO Auto-generated method stub                      
    }
    });
    builder.setNeutralButton("Show Both", new DialogInterface.OnClickListener()
    {
    
    @Override
    public void onClick(DialogInterface arg0, int arg1)
    {
        // TODO Auto-generated method stub                      
    }
    });
    builder.show();
    

    UPDATE: To show custom title create a layout and inflate it using below code

    LayoutInflater mInflater = LayoutInflater.from(mContext);
    View layout = mInflater.inflate(R.layout.popup_example, null);
    

    Remove following line from above code

    builder.setTitle("Alert !");
    

    and then set using

    builder.setCustomTitle(layout)
    

提交回复
热议问题