blog

Home / DeveloperSection / Blogs / Add custom control on Dialog in android

Add custom control on Dialog in android

Manoj Pandey2618 12-Jul-2015

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.


Dialogs inform users about critical information, require users to make decisions, or encapsulate multiple tasks within a discrete process. Use dialogs sparingly because they are interruptive in nature. Their sudden appearance forces users to stop their current task and refocus on the dialog content. Not every choice, setting, or detail warrants interruption and prominence.


 Alternatives to dialogs include menus or inline expansion within the current content area. Both approaches present non-interruptive options while maintaining the current context.


You can add custom control in dialog for example edittext , textview buttons etc. Here I am creating a dialog with using custom button.

final Dialog dialog = new Dialog(MainActivity.this);
 
LinearLayout popUp = new LinearLayout(MainActivity.this);
popUp.setBackgroundColor(Color.LTGRAY);
popUp.setOrientation(1);
 
LinearLayout btnLayout = new LinearLayout(MainActivity.this);
btnLayout.setBackgroundColor(Color.LTGRAY);
btnLayout.setOrientation(1);
btnLayout.setGravity(Gravity.CENTER);
 
Button btnOne = new Button(MainActivity.this);
send.setText("Button1");
send.setTextColor(Color.WHITE);
Button btnTwo = new Button(MainActivity.this);
cancel.setText("Button2");
cancel.setTextColor(Color.WHITE);
dialog.setTitle("Select Action");
btnLayout.addView(send);
btnLayout.addView(cancel);
popUp.addView(btnLayout);
dialog.setContentView(popUp);
 
btnOne.setOnClickListener(new OnClickListener() {

@Override
    publicvoid onClick(View v) {
   TODO Auto-generated method stub
   Toast.makeText(MainActivity.this, "Button one clicked",                  Toast.LENGTH_LONG).show();
}
});
 
btnTwo.setOnClickListener(new OnClickListener() {
 
       @Override
       publicvoid onClick(View v) {
       // TODO Auto-generated method stub
       Toast.makeText(MainActivity.this, "Button two clicked", Toast.LENGTH_LONG).show();
 
       }
       });
               
       dialog.show();

 

   You can see dialog.


    Add custom control on Dialog in android


Leave Comment

Comments

Liked By