星期三, 5月 01, 2013

Android TransparentDialog


package com.TransparentDialog;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;


public class TransparentDialogActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button buttonStartDialog = (Button)findViewById(R.id.start);
    buttonStartDialog.setOnClickListener(new Button.OnClickListener(){


 @Override
 public void onClick(View arg0) {
  //Create AlertDialog
  AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(TransparentDialogActivity.this);
  myAlertDialog.setTitle("--- Title ---");
   
  myAlertDialog.setMessage("Alert Dialog Message");
   
  myAlertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
   // do something when the button is clicked
   public void onClick(DialogInterface arg0, int arg1) {
    //...
   }});
   
  myAlertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
   // do something when the button is clicked
   public void onClick(DialogInterface arg0, int arg1) {
    //...
   }});
   
  AlertDialog dialog = myAlertDialog.show();
   
  WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
  params.alpha = 0.6f;
  dialog.getWindow().setAttributes(params);
 }});
}
  
}

沒有留言: