Custom Dialog Box Android

 

Buat methode dengan nama  myTextDialog, kemudian panggil method tersebut .


protected void myTextDialog()
{
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.layout_dialogbox);
dialog.setTitle("Text Dialog");
Button ok = (Button)dialog.findViewById(R.id.buttonOK);
ok.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
dialog.dismiss();

}
});
dialog.show();

}

layout_dialogbox.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:ems="10" />

<EditText
android:id="@+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:ems="10" />

<Button
android:id="@+id/buttonOK"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="OK" />

</LinearLayout>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s