3

This question specific to the issue with Xiomi devices with MIUI over it.

How can I detect Fullscreen Mode (Gesture) or Navigation Button (soft navigation) is selected?

I Have tried a few solutions, but that does work on other devices but didn't work on Xiomi or MIUI.

I have tried this solution available on SO, so please provide another if you have.

1

public boolean hasNavBar (Resources resources) 
{
    int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
    return id > 0 && resources.getBoolean(id);
}

2

boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);

if (hasBackKey && hasHomeKey) {
    // no navigation bar, unless it is enabled in the settings
} else {
    // 99% sure there's a navigation bar
}

3

View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
        (new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
                    // TODO: The navigation bar is visible. Make any desired
                    // adjustments to your UI, such as showing the action bar or
                    // other navigational controls.
                } else {
                    // TODO: The navigation bar is NOT visible. Make any desired
                    // adjustments to your UI, such as hiding the action bar or
                    // other navigational controls.
                }
            }
        });

Any idea of how can I get to know that the navigation bar is currently visible or not?

I also tried to calculate the real width and available width, it seems like MIUI always returning the reserved with of navigation bar.

Thanks.

Prajwal
  • 246
  • 1
  • 5
  • 16
Tapas Thakkar
  • 845
  • 8
  • 19

2 Answers2

0

There is no need to detect if Soft input navigation bar is visible or hidden for full screen activity you can create style and apply style to activity.

 <style name="Theme" parent="Theme.AppCompat.Light.NoActionBar">
         <item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="lollipop">false</item>
         <item name="android:windowTranslucentStatus">true</item>
     </style>

and add following line in activity :

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
                    WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }

This is led you to stop the layout overlap from soft input navigation.

PArth SOni
  • 117
  • 1
  • 11
0

I have the same problem too. I found 2 solution:

  1. This solution works for me for versions above Android Q.

    public static int isEdgeToEdgeEnabled(Context context) {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("config_navBarInteractionMode", "integer", "android");
        if (resourceId > 0) {
            return resources.getInteger(resourceId);
        }
        return 0;
    }
    

If this method returns 2 then Full screen mode is enabled.

2.This solution works for me above Android Q and below it:

ViewCompat.setOnApplyWindowInsetsListener(
    findViewById(android.R.id.content)
) { _: View?, insets: WindowInsetsCompat ->
    navigationBarHeight = insets.systemWindowInsetBottom
    insets
}

I used 2 method myself