Customized dialog within the Activity

Web Hosting
In this post, I will show you how to create a customized dialog in Android. I can't show you the output because I can't upload image at this time. I will just show you some codes.

//declare a dl variable for dialog at the top
private Dialog dl;


//user this code whereever you need it.
dl = new Dialog(Send_Money.this);
dl.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dl.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dl.setContentView(getLayoutInflater().inflate(R.layout.send_money_option_dialog, null));
dl.getWindow().getAttributes().windowAnimations = R.style.dialog_animation;

TextView tv_msg = (TextView)dl.findViewById(R.id.tv_message);
TextView tv_title = (TextView)dl.findViewById(R.id.tv_dialog_title);


tv_title.setText("TITLE");
tv_msg.setText("Message");

Button btn_one = (Button) dl.findViewById(R.id.btn_dialog_btn_one);
Button btn_two = (Button) dl.findViewById(R.id.btn_dialog_btn_two );
Button btn_three = (Button) dl.findViewById(R.id.btn_dialog_btn_three);

btn_one .setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

//do some code for button one

}
});


btn_two .setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

//do some code for button two

}
});

btn_three .setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

//do some code for button three

}
});

dl.show();
}


Web Hosting
That's it, hope this simple tutorial will help youo. Happy Coding.    

No comments:

Post a Comment