1

In my android app, i am using custom dialog in my activity. I have given style to this custom dialog for transparent background. I am facing weird issue on Kitkat 4.4. The dialog gets cut from top side only on Kitkat 4.4.Devices with sdk level < 4.4 gives proper output according to my requirement. Why its is like this? Pleas help me to solve this issue.I tried this link but not getting how to implement it with my requirement. Thank you.

Code:

 public void showGameOverDialog(int score) {

        final Dialog dialog = new Dialog(Level1Activity_Room.this,
                R.style.DialogBackground);
        dialog.setContentView(R.layout.gameover_dialog_layout);         
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.show();
}

R.style.DialogBackground :

 <style name="DialogBackground" parent="@android:style/Theme.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>
Community
  • 1
  • 1
Zankhna
  • 4,570
  • 9
  • 62
  • 103

3 Answers3

1

Finally i solved this issue with some modification in my existing code. Also changed Target level to Android 4.4 from Project->Right Click->Android

    public void showGameOverDialog(int score) {
        final Dialog dialog = new customeDialogClass(Level1Activity_Room.this,
                R.style.DialogBackground);
        dialog.setContentView(R.layout.gameover_dialog_layout);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
dialog.show();
}

customeDialogClass.java

 @TargetApi(14)
public class customeDialogClass extends Dialog {

    public customeDialogClass(Context context) {
        super(context);
        if (Build.VERSION.SDK_INT < 18) {
            return;
        }

        // The UI options currently enabled are represented by a bitfield.
        // getSystemUiVisibility() gives us that bitfield.
        int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
        int newUiOptions = uiOptions;
        boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
        if (isImmersiveModeEnabled) {
            Log.e("log1---", "Turning immersive mode mode off.");
        } else {
            Log.e("log2-----", "Turning immersive mode mode on.");
        }

        // Status bar hiding: Backwards compatible to Jellybean
        if (Build.VERSION.SDK_INT >= 16
                && (newUiOptions & View.SYSTEM_UI_FLAG_FULLSCREEN) <= 0) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
        }

        if (Build.VERSION.SDK_INT >= 18
                && (newUiOptions & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) <= 0) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }

        getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
    }

    public customeDialogClass(Context context, boolean cancelable,
            OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public customeDialogClass(Context context, int theme) {
        super(context, theme);
        if (Build.VERSION.SDK_INT < 18) {
            return;
        }

        // The UI options currently enabled are represented by a bitfield.
        // getSystemUiVisibility() gives us that bitfield.
        int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
        int newUiOptions = uiOptions;
        boolean isImmersiveModeEnabled = ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
        if (isImmersiveModeEnabled) {
            Log.e("log1---", "Turning immersive mode mode off.");
        } else {
            Log.e("log2-----", "Turning immersive mode mode on.");
        }

        // Status bar hiding: Backwards compatible to Jellybean
        if (Build.VERSION.SDK_INT >= 16
                && (newUiOptions & View.SYSTEM_UI_FLAG_FULLSCREEN) <= 0) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
        }

        if (Build.VERSION.SDK_INT >= 18
                && (newUiOptions & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) <= 0) {
            newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        }
        getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
    }

}
Zankhna
  • 4,570
  • 9
  • 62
  • 103
0

Problem not in kitkat 4.4, i think problem is in the R.layout.gameover_dialog_layout for screen support

Karthick pop
  • 616
  • 3
  • 16
0

It usually goes through a title bar that is added in Android 4.4 or lower versions. It is solved by adding the following line to the custom dialog.

dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
ja12
  • 351
  • 2
  • 16