Android: how to create a transparent dialog-themed activity
The easiest way that I have found is to set the activity's theme in the AndroidManifest to android:theme="@android:style/Theme.Holo.Dialog"
then in the activity's onCreate method call getWindow().setBackgroundDrawable(new ColorDrawable(0));
Just one thing to add to all the answers here. To achieve a full dialog like behaviour, you can reposition the dialog by changing the window layout params:
WindowManager.LayoutParams params = getWindow().getAttributes();
params.x = ...;
params.y = ...;
params.width = ...;
params.height = ...;
this.getWindow().setAttributes(params);
We used a similar technique to achieve a floating activity effect in the Tooleap SDK:
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
and import android.graphics.drawable.ColorDrawable; on top :)
You can create a tranparent dialog by this.
public class DialogActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(" ");
alertDialog.setMessage("");
alertDialog.setIcon(R.drawable.icon);
alertDialog.setButton("Accept", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.setButton2("Deny", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
}
After this just put a line in AndroidManifest.xml, where you define your activity in manifest.
android:theme="@android:style/Theme.Translucent.NoTitleBar"