Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to add my own style pop-up dialogue box in my android app as shown in image [duplicate]

As shown in image the above part is my layout and i want to add pop-up like part below in image.So how can i create it and how can i handle dialogue box button event.??

enter image description here

like image 917
Razin Avatar asked Feb 18 '23 01:02

Razin


2 Answers

public class Add extends Activity{

PopupWindow popUp;
Dialog myDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.add);

    myDialog = new Dialog(Add.this);
    myDialog.setContentView(R.layout.popup50);
    myDialog.setTitle("Please Pay Attention!");
    myDialog.setCancelable(true);

    //for save
  Button popone = (Button)myDialog.findViewById(R.id.button1);
  popone.setOnClickListener(new OnClickListener()
  {
  public void onClick(View v) 
  {

      myDialog.dismiss();

     }
  });


  //for cancel
  Button poptwo = (Button)myDialog.findViewById(R.id.button2);
  poptwo.setOnClickListener(new OnClickListener()
  {
  public void onClick(View v) 
  {


    Intent CheckProfile = new Intent(Add.this, UserActivity.class);
    startActivity(CheckProfile);
    myDialog.dismiss();


     }
  });


  myDialog.show();


}   

and this is XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:background="#00FFFF"
android:layout_width="300dp"
android:layout_height="wrap_content" >

<TextView
    android:id="@+id/popUp_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp"
    android:gravity="center"
    android:textColor="#000000"
    android:text="@string/pop50"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/popUp_text"
    android:layout_marginRight="36dp"
    android:layout_marginTop="44dp"
    android:text="Cancel" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button2"
    android:layout_alignBottom="@+id/button2"
    android:layout_marginRight="69dp"
    android:layout_toLeftOf="@+id/button2"
    android:text="  Ok  " />

</RelativeLayout>
like image 200
Droid Avatar answered Feb 22 '23 13:02

Droid


I have something similar to show an about screen that might be helpful for you:

b.setOnClickListener(new View.OnClickListener() {  
    public void onClick(View v) {
        show_about();              
    }
});

...

private void showAbout() {
    Dialog dialog = new Dialog (context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.about);
    dialog.setCanceledOnTouchOutside(true);
    dialog.show();      
}

The xml bit:

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="23dp"
        android:text="An app for the Newcastle Cloud Team"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:src="@drawable/coche3" />

    ...

  </RelativeLayout>
like image 31
ophintor Avatar answered Feb 22 '23 14:02

ophintor