Skip to main content

Android Custom Alert Dialog Display Error after changing the Build Version



I am developing one simple demo . Here in this demo i just create one simple custom alert dialog . Its work 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 its 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.



Source: Tips4all

Comments

  1. 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);

    ReplyDelete
  2. Apparently, this is a known issue.


    This only happens when you try inheriting from the framework themes.
    Using @android:style directly will still treat them as non-
    fullscreen, which punches through the black background as expected.

    One workaround is to start with a nearly-blank theme (like Panel or
    Translucent) and then render what you need in your own layout (such as
    dialog edges, etc).


    Thought, I still don't fully understand this solution myself yet.

    And actually, I'm no longer sure they're talking about the exact same bug you've seen, since they're talking about it not working for an older version of the sdk (not a newer one like yours). See the bug report.

    ReplyDelete
  3. 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>

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex