开发者

How to create the above custom dialog in android?

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 picture?

I have done some research and it made me wonder should i be using a custom xml to create a custom dialog view or should i be using alertdialog to create the exact view programmability shown above? And even if alertdialog is possible how am i going to accommodate with so many textview messages shown in the middle of the dialog picture given alertdialog limitation? Eg: "builder.setMessage("This is the alert's body");" If you know what i mean!!

Can someone tell me the easiest way to get the exact s开发者_StackOverflow中文版ame view because i'm kinna doing the same app and new to android.. Thanks :)


The best approach will be custom dialog. As it will be helpful creating all those background colours and the effect. I am sure the link you have posted is using custom dialog as well,

cheers

link that might help:

[1] http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

[2] http://androidideasblog.blogspot.com/2010/02/creating-custom-dialog-in-android.html

/// In your code implementations just add this code when you create dialog....after having this just have all TextView arranged in your layout and add that layout id to this below code good luck

//Dialog box creator
private Dialog constructYourDialog()
{
    //Preparing views
  LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
  View layout = inflater.inflate(R.layout.***your_xml_name***, (ViewGroup) findViewById(R.id.***Yout view id***));
    //Building dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(layout);

    builder.setPositiveButton("Show Videos", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
                Log.i("","Show Video Click");
                dialog.dismiss();
    });
    builder.setNegativeButton("E-Mail", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
           Log.i("","E-mail Click");
           dialog.dismiss();
        }
    });
     builder.setNeutralButton("Show Map", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Log.i("","Show Map Click");
            dialog.dismiss();
        }
    });
          AlertDialog alert = builder.create();
    return alert;

}


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜