1.Create a Class Dialog_Utils
public class Dialog_Utils {
/**
* to display dialog
* @param context
* @param title
* @param message
* @param status
*/
public void show_Dialog(final Context context, String title, String message) {
final Dialog dialog = new Dialog(context);
dialog.setCanceledOnTouchOutside(false);
dialog.setContentView(R.layout.common_dialog);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
final TextView txt_tittle = (TextView)dialog.findViewById(R.id.textView1);
final TextView txt_message = (TextView)dialog.findViewById(R.id.textView2);
final Button btn_close = (Button)dialog.findViewById(R.id.button1);
txt_tittle.setText(title);
txt_message.setText(message);
btn_close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
2.Now use these in your MainActivity
public class MainActivity extends Activity {
// Alert Dialog Manager
Dialog_Utils dialog = new Dialog_Utils();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialog.show_Dialog(MainActivity.this, "Tittle",
"MESSAGE/SUBJECT");
}
}
Now, are able to create acustom dialog android application.
public class Dialog_Utils {
/**
* to display dialog
* @param context
* @param title
* @param message
* @param status
*/
public void show_Dialog(final Context context, String title, String message) {
final Dialog dialog = new Dialog(context);
dialog.setCanceledOnTouchOutside(false);
dialog.setContentView(R.layout.common_dialog);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
final TextView txt_tittle = (TextView)dialog.findViewById(R.id.textView1);
final TextView txt_message = (TextView)dialog.findViewById(R.id.textView2);
final Button btn_close = (Button)dialog.findViewById(R.id.button1);
txt_tittle.setText(title);
txt_message.setText(message);
btn_close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
2.Now use these in your MainActivity
public class MainActivity extends Activity {
// Alert Dialog Manager
Dialog_Utils dialog = new Dialog_Utils();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialog.show_Dialog(MainActivity.this, "Tittle",
"MESSAGE/SUBJECT");
}
}
Now, are able to create acustom dialog android application.
No comments:
Post a Comment