This post will show the android custom dialog with custom layout.
In the xml file you can create any type of layout.
XML
<<
? xml version = "1.0"
encoding = "utf-8" ? >
<
RelativeLayout xmlns : android = "http://schemas.android.com/apk/res/android"
android: layout_width = "match_parent"
android: layout_height = "match_parent" >
<
LinearLayout
android: layout_width = "match_parent"
android: layout_height = "wrap_content"
android: layout_margin = "10dp"
android: layout_below = "@+id/editText11"
android: background = "@android:color/transparent"
android: orientation = "horizontal"
android: id = "@+id/linearLayout2" >
<
Button android: id = "@+id/ok"
android: layout_width = "match_parent"
android: layout_height = "50dp"
android: layout_weight = "1"
android: background = "@color/colorPrimary"
android: padding = "5dp"
android: text = "ok"
android: textColor = "@android:color/white"
android: textSize = "15dp"
android: textStyle = "bold" / >
<
Button android: id = "@+id/gallery"
android: layout_width = "match_parent"
android: layout_height = "50dp"
android: layout_marginLeft = "5dp"
android: layout_weight = "1"
android: background = "@color/colorPrimary"
android: padding = "5dp"
android: text = "Gallery"
android: visibility = "invisible"
android: textColor = "@android:color/white"
android: textSize = "15dp"
android: textStyle = "bold" / >
<
Button android: id = "@+id/cancel"
android: layout_width = "match_parent"
android: layout_height = "50dp"
android: layout_marginLeft = "5dp"
android: layout_weight = "1"
android: background = "@color/colorPrimary"
android: padding = "5dp"
android: text = "Cancel"
android: textColor = "@android:color/white"
android: textSize = "15dp"
android: textStyle = "bold" / >
<
/LinearLayout>
<
EditText android: layout_width = "match_parent"
android: textColor = "#000"
android: gravity = "center"
android: layout_height = "wrap_content"
android: inputType = "textPersonName"
android: hint = "Enter video link"
android: singleLine = "true"
android: ems = "10"
android: layout_centerHorizontal = "true"
android: id = "@+id/editText11" / >
< /RelativeLayout>
Java Class
The java class past this code on any button click.
final Dialog dialog;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Call some material design APIs here dialog = new Dialog(AddAPlayerMain.this,
android.R.style.Theme_Material_Light_Dialog_Alert);
} else {
dialog = new Dialog(AddAPlayerMain.this);
}
dialog.setContentView(R.layout.video_add_dialog);
dialog.setTitle("Enter video link");
// TODO Auto-generated method stub
Button ok = (Button) dialog.findViewById(R.id.ok);
final EditText link = (EditText) dialog.findViewById(R.id.editText11);
Button cancel = (Button) dialog.findViewById(R.id.cancel);
dialog.setCanceledOnTouchOutside(true);
// ** Camera Listener Start **//
ok.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
// ** Cancel Listener Start **//
cancel.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
// ** Cancel Listener End**//
dialog.show();
No comments:
Post a Comment