Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dialog on Android KitKat seems to be cut

I used dialog theme for an Activity and it works fine on Android <= 4.3 but not on the latest KitKat 4.4. Here's a screenshot of the problem:

dialog android 4.4 problem

Top of the layout is missing. You can see that the bounds seems to be cut.

I'm using an Android emulator to test the app, so I don't know if the problem is due to the virtual machine or due to some other reason.

like image 819
Hacketo Avatar asked Nov 21 '13 13:11

Hacketo


People also ask

What is KitKat in Android phone?

Android 4.4 KitKat is a version of Google's operating system (OS) for smartphones and tablets. The Android 4.4 KitKat operating system uses advanced memory optimization technologies. As a result, it is available on Android devices with as little as 512 MB of RAM.


4 Answers

You can solve the problem to be cut from below code.

dialog.getWindow().setFlags(     WindowManager.LayoutParams.FLAG_FULLSCREEN,      WindowManager.LayoutParams.FLAG_FULLSCREEN); 
like image 173
Mu-ik Jeon Avatar answered Sep 23 '22 02:09

Mu-ik Jeon


You should extend the Dialog and in the onCreate call the following method:

@TargetApi(14) public void toggleHideBar() {      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.d("dialog", "Turning immersive mode mode off.");     } else {         Log.d("dialog", "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;     }      // Immersive mode: Backward compatible to KitKat.     // Note that this flag doesn't do anything by itself, it only augments the behavior     // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample     // all three flags are being toggled together.     // Note that there are two immersive mode UI flags, one of which is referred to as "sticky".     // Sticky immersive mode differs in that it makes the navigation and status bars     // semi-transparent, and the UI flag does not get cleared when the user interacts with     // the screen.     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); } 
like image 25
Ronen A. Avatar answered Sep 22 '22 02:09

Ronen A.


Finally, I tried to do something with the new FullScreen Immersive mode available in Android 4.4. Android FullScreen

Just put this in the onResume of the "dialog" activity, and that allow you to use dialogs in a fullscreen activity, without the top cutting :)

Edit : Added a compatibility check for the target version, setSystemUiVisibility is implemented in Api 11, but it seem to need that "patch" only for android 4.4 )

// Only for Api >=4.0 
if (android.os.Build.VERSION.SDK_INT >= 16) {
    int mUIFlag = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // I removed this
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LOW_PROFILE
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; // and this to keep the navigation bar
    getWindow().getDecorView().setSystemUiVisibility(mUIFlag);
}
like image 33
Hacketo Avatar answered Sep 24 '22 02:09

Hacketo


I have a similar problem, but with using a custom dialog. Unfortunately, I couldn't post my screenshot here.

I tested with a few different options, and looks like running the parent activity in fullscreen mode affects this. If I remove the following code, the dialog seems to work fine.

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

I noticed this after getting the 4.4 KitKat update on a Google Nexus 7 (first version). Also, it doesn't seem to make a difference if I have the dialog's title present or not.

like image 29
Tuomas Tikka Avatar answered Sep 23 '22 02:09

Tuomas Tikka