My original goal here was a modal dialog, but you know, Android didn't support this type of dialog. Alternatively, building a dialog-themed activity would possibly work.
Here's code,
public class DialogActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(android.R.style.Theme_Dialog);
super.onCreate(savedInstanceState);
requestWindowFeature (Window.FEATURE_NO_TITLE);
Button yesBtn = new Button(this);
yesBtn.setText("Yes");
yesBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DialogActivity.this.finish();
}
});
this.setContentView(yesBtn);
}
However, the background was always black, that really confusing. People got same problem,
http://code.google.com/p/android/issues/detail?id=4394
I just wanna make it look more dialog-like for user. So, how to get this DialogActivity transparent and never cover underlying screen?
Thanks.
This was how I created the style
<style name="CustomDialogTheme" parent="android:Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
</style>
3 by just adding android:theme="@android:style/Theme. Translucent" in the activity tag in the manifest. This works fine for 2.2 also.
In Android, we can create a transparent activity that will not be visible but your application will be running. The best part of this transparent activity is that you can create a transparent activity by just changing the resource file and we need not write the java or kotlin code for the same.
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"
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With