I am developing a simple demo . Here in this demo, I am just creating one simple custom alert dialog . It works fine.
It shows me the perfect result when i build application in 1.6, but when i change the android version from 1.6 to 2.2, it shows the unexpected result. It doesn't show the background screen on which i display the custom alert dialog.
Here is my xml file. Custom Dialog Theme File
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomDialogTheme" parent="@android:style/AlertDialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@android:style/Theme.Dialog</item>
</style>
</resources>
Here is My CustomConfirmOkDialog Class
package com.utility.org;
import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class CustomConfirmOkDialog extends Dialog implements OnClickListener
{
private Button okButton = null;
private TextView infoText=null,confirmBody=null;
private int errorMessage=0;
@SuppressWarnings("unused")
private Activity activity;
public CustomConfirmOkDialog(Activity context,int customdialogtheme,int errorMessage)
{
super(context,customdialogtheme);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.confirm_ok);
this.errorMessage = errorMessage;
this.activity = context;
initControls();
}
private void initControls()
{
okButton = (Button) findViewById(R.id.ok_button);
okButton.setOnClickListener(this);
infoText = (TextView)findViewById(R.id.infoText);
confirmBody = (TextView)findViewById(R.id.confirmBody);
switch (this.errorMessage)
{
case Utility.INVALID_USERNAME_PASSWORD:
try
{
infoText.setText(R.string.signIn);
confirmBody.setText(R.string.invalidUsernameAndPassword);
}
catch (Exception e)
{
e.printStackTrace();
}
break;
default:
break;
}
}
public void onClick(View v)
{
dismiss();
}
}
Calling this class from my main activity using the below code.
CustomConfirmOkDialog dialog = new CustomConfirmOkDialog(MainActivity.this, R.style.CustomDialogTheme, Utility.INVALID_USERNAME_PASSWORD);
dialog.show();
Here you can clearly notice that 1st image
shows the background . Its build in android 1.6 version while 2nd image
doesn't shows the background . It shows the entire black screen. Its build in android version 2.2 . I am very thankful if anyone can solve this issue.
Can anyone help me to solve this simple and silly issue ?
Thanks in Advance.
item_img_close); closeIcon_img. setOnClickListener(new View. OnClickListener() { // I want To dismiss Here }); dialog. show(); } });
Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.
AlertDialog alertDialog = alertDialogBuilder. create(); alertDialog. show(); This will create the alert dialog and will show it on the screen.
It resolved my problem by changing the following code in Custom Dialog Theme xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomDialogTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
<item name="android:windowFrame">@null</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
I also faced the same problem. the problem is when I called constructor of Dialog class
Dialog(Context context, int themeId)
it will hide the background activity. The only solution that i found is don't call this constructor, instead only call
Dialog(Context context)
and set your style in the layout file.
So in your code, only write
super(context)
instead of
super(context, themeid);
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