Search code examples
androidandroid-alertdialogandroid-buildandroid-version

Android Custom Alert Dialog Display Error after changing the Build Version


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();

enter image description here enter image description here

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.


Solution

  • 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>