I need a Dialog box in my app that is diversified in it's appearance, I mean that for example for one time I need a dialog box with only on button and for the other time I need it to have 2 buttons. also I want some of it's features like it's image be differend depending on it's usage! Could any one suggests me How I can implement it? For my solution I've searched some web sites and I implemented the dialog box which was implemented in CustomDialogClass from the code in the link below, but it doesn't show the dialog box, Could any one help me how I can show it?
            Asked
            
        
        
            Active
            
        
            Viewed 104 times
        
    4 Answers
1
            
            
        try this android dialog lib. very simple to use with few lines of code in your activity.
Pop.on(this)
    .with()
    .title(R.string.title) // if non needed skip this
    .layout(R.layout.custom_pop)
    .when(new Pop.Yah() { // if not needed skip this
        @Override
        public void clicked(DialogInterface dialog, View view) {
            Toast.makeText(getBaseContext(), "Yah button clicked", Toast.LENGTH_LONG).show();
        }
    })
    .when(new Pop.Nah() { // if not needed, skip this
        @Override
        public void clicked(DialogInterface dialog, View view) {
            Toast.makeText(getBaseContext(), "Nah button clicked", Toast.LENGTH_LONG).show();
        }
    }).show();
 
    
    
        Tunaki
        
- 132,869
- 46
- 340
- 423
 
    
    
        Dharmesh Gohil
        
- 324
- 2
- 6
0
            
            
        You can add different layout for each of the dialog. one layout for 1 button other is with buttons and images, etc.
example:
        final Dialog dialog = new Dialog(context);
        dialog.setContentView(R.layout.custom); //the layout of your custom dialog
        dialog.setTitle("Title...");
        dialog.show();
You can find more info here on how to implement the action within the dialog.
 
    
    
        Rod_Algonquin
        
- 26,074
- 6
- 52
- 63
0
            I think what you need is a Dialog, not a Dialog themed Activity. As when that happens, you would have to initiate the (new) activity every time you want to show the dialog.  
Instead, you can use Dialog like:  
// custom dialog
final Dialog dialog = new Dialog(context);
//specify to not display the default title/header to customize the whole layout
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.setContentView(R.layout.custom_layout_here);
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText(message);
//from the following part- buttons can be managed for your custom layout
Button dialogButton = (Button) dialog.findViewById(R.id.buttonOk);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
//if you want another button, add it here, just like the one above
//play with the visibility of button(or components) to hide or show acc to your requirement
dialog.show();
 
    
    
        Pararth
        
- 8,114
- 4
- 34
- 51
- 
                    Thanks for your solution, Do you mean I create a method which contents are the code you have mentioned? and each time when I want to call the Dialog, I should just call it in my app? – user3737467 Jun 14 '14 at 21:55
- 
                    yes, depending on when you want one button or two, you can put the above code in a function, with flags depending on which you will show buttons and pass the context, message, and other parameters that you need to set, that would work – Pararth Jun 14 '14 at 22:05
0
            
            
            final Dialog d = new Dialog(DisplayUserData.this);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE); //before
    d.setContentView(R.layout.edit_msg_dialog);
    ImageView ivCross = (ImageView) d.findViewById(R.id.ivCross_msg);
    final EditText et_Message = (EditText) d.findViewById(R.id.etMessage);
    TextView tv_OK = (TextView) d.findViewById(R.id.tvOkButton);
    TextView tv_SKIP = (TextView) d.findViewById(R.id.tvSkipButton);
    tv_OK.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(et_Message.getText().toString().length()>= 40){
                Toast.makeText(getApplicationContext(),"You Can not enter                                          more then 40 characters.", Toast.LENGTH_SHORT).show();
            }else if(et_Message.getText().toString().length()< 1){
                Toast.makeText(getApplicationContext(),"Please Enter something", Toast.LENGTH_SHORT).show();
            }else {
                d.dismiss();
                msgWritten = et_Message.getText().toString();
                submittData();
            }
        }
    });
    ivCross.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            d.cancel();
        }
    });
    tv_SKIP.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            d.cancel();
            submittData(); 
        }
    });
    d.show();
    d.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    WindowManager.LayoutParams lp = d.getWindow().getAttributes();
    lp.dimAmount = 0.7f;
    d.getWindow().setAttributes(lp);
 
    
    
        Deepika kapila
        
- 59
- 3
 
    