pro para pantalla oreo optimizada ocultar nova navegacion modo inmersivo immersive gmd esta ejecutarse completa barra aplicacion android view keyboard

para - ocultar barra de navegacion android



Ocultar barra de navegaciĆ³n de Android/Permanecer en modo inmersivo con apariencia de teclado suave (4)

Trabajando en la aplicación de un cliente que utiliza el modo inmersivo para ocultar la barra de navegación y la barra de estado en cada actividad mediante el siguiente código:

int currentApiVersion = android.os.Build.VERSION.SDK_INT; final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; // This work only for android 4.4+ if (currentApiVersion >= 19) { getWindow().getDecorView().setSystemUiVisibility(flags); // Code below is for case when you press Volume up or Volume down. // Without this after pressing valume buttons navigation bar will // show up and don''t hide final View decorView = getWindow().getDecorView(); decorView .setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { decorView.setSystemUiVisibility(flags); } } }); }

El único problema es que les gustaría que la aplicación permanezca en modo inmersivo y no muestre la barra de navegación, incluso cuando el teclado virtual muestra que se escribe en un texto de edición. ¿Alguien puede pensar en una forma de tener siempre ocultos los botones de navegación (atrás / ocultar teclado, inicio, etc.) incluso cuando se usa el teclado?


Aquí está mi solución para esto; Primero verifiqué si se muestra o no el teclado suave:

getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect r = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(r); int screenHeight = getWindow().getDecorView().getRootView().getHeight(); int keypadHeight = screenHeight - r.bottom; //Log.d(TAG, "keypadHeight = " + keypadHeight); if (keypadHeight > screenHeight * 0.15) { //Keyboard is opened hideNavBar(); } else { // keyboard is closed } } });

Y tengo un método hideNavBar () que se activa cuando aparece el teclado virtual.

private void hideNavBar() { if (Build.VERSION.SDK_INT >= 19) { View v = getWindow().getDecorView(); v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } }

Esto resuelve el problema de obtener la barra de navegación mientras se escribe un Edittext.


He ideado una solución alternativa que verifica el estado de la barra de navegación para cada uno interno, trate de ocultarlo y verifíquelo nuevamente (y nuevamente).

Aquí hay un fragmento de código que garantiza que la barra de navegación se oculte 2 segundos después de que se cierre el teclado virtual.

private final Runnable checkSystemUiRunnable = new Runnable() { @Override public void run() { checkHideSystemUI(); } }; private void checkHideSystemUI() { // Check if system UI is shown and hide it by post a delayed handler if (isSystemUiShown) { hideSystemUI(); handler.postDelayed(checkSystemUiRunnable, SYSTEM_UI_HIDE_DELAY); } } private void hideSystemUI() { decorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar | View.SYSTEM_UI_FLAG_IMMERSIVE); } // In onCreate() decorView.setOnSystemUiVisibilityChangeListener( new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { handler.postDelayed(checkSystemUiRunnable, SYSTEM_UI_HIDE_DELAY); isSystemUiShown = true; } else { isSystemUiShown = false; } } });


Ver this He buscado más de 3 horas para este problema y esa solución funcionó bien. Espero que sea de ayuda.


Actualizado :

Tengo una aplicación para pintar ( Formas de pintura ) y esta es la configuración que solía estar siempre dentro del modo inmersivo. Yo uso el método onWindowFocusChanged .

@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } }