2015-12-22 14 views
13

Sto cercando di implementare una modalità a schermo intero, ma per Android 4.4 e versioni successive, si vede uno spazio vuoto c'è:modalità immersiva che mostra lo spazio vuoto

PRIMA modalità immersiva (a tutto schermo)

enter image description here

e DOPO il toggleFullScreen (falso);

enter image description here

come si può vedere, la sua non rimuoverla. Ecco il codice che sto usando per attivarlo:

public void toggleFullscreen(boolean fs) { 
     if (Build.VERSION.SDK_INT >= 11) { 
      // The UI options currently enabled are represented by a bitfield. 
      // getSystemUiVisibility() gives us that bitfield. 
      int uiOptions = this.getWindow().getDecorView().getSystemUiVisibility(); 
      int newUiOptions = uiOptions; 
      boolean isImmersiveModeEnabled = 
        ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions); 
      if (isImmersiveModeEnabled) { 
       Log.i(getPackageName(), "Turning immersive mode mode off. "); 
      } else { 
       Log.i(getPackageName(), "Turning immersive mode mode on."); 
      } 

      // Navigation bar hiding: Backwards compatible to ICS. 
      if (Build.VERSION.SDK_INT >= 14) { 
       newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; 
      } 

      // Status bar hiding: Backwards compatible to Jellybean 
      if (Build.VERSION.SDK_INT >= 16) { 
       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; 
      } 
      getWindow().getDecorView().setSystemUiVisibility(newUiOptions); 
     } else { 
      // for android pre 11 
      WindowManager.LayoutParams attrs = getWindow().getAttributes(); 
      if (fs) { 
       attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; 
      } else { 
       attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; 
      } 
      this.getWindow().setAttributes(attrs); 
     } 

     try { 
      // hide actionbar 
      if 
        (this instanceof AppCompatActivity) { 
       if (fs) getSupportActionBar().hide(); 
       else getSupportActionBar().show(); 
      } else if 
        (Build.VERSION.SDK_INT >= 11) { 
       if (fs) getActionBar().hide(); 
       else getActionBar().show(); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
+0

hai trovato una soluzione per questo. Sto affrontando lo stesso problema – glo

+0

@glo la soluzione indicata di seguito sta funzionando per me. controllare [questo] (https://gitlab.com/ankit_aggarwal/ToggleFullScreenDemo.git) codice –

+0

@glo sta succedendo in Android L e solo sopra o anche per versioni inferiori? In tal caso, sta succedendo solo con lo stato o con la barra di navigazione in basso? –

risposta

24

Si prega di verificare che non si dispone di android:fitsSystemWindows="true" nel layout.

Almeno ha risolto il mio caso - Avevo fitSystemWindows su FrameLayout.

0

È necessario aggiungere questo flag alla vista View.SYSTEM_UI_FLAG_LAYOUT_STABLE. Prova in questo modo

// This snippet hides the system bars. 
private void hideSystemUI() { 
// Set the IMMERSIVE flag. 
// Set the content to appear under the system bars so that the content 
// doesn't resize when the system bars hide and show. 
mDecorView.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); 
} 

// This snippet shows the system bars. It does this by removing all the flags 
// except for the ones that make the content appear under the system bars. 
private void showSystemUI() { 
mDecorView.setSystemUiVisibility(
     View.SYSTEM_UI_FLAG_LAYOUT_STABLE 
     | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
     | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); 
} 
+0

hi @android_Muncher, non ha risolto, = (, im usando Fragment ma chiamando la schermata togglefull dall'attività, mostra ancora uno spazio grigio dove erano i pulsanti soft e uno spazio nero dove la barra delle notifiche era – user2582318

+0

mDecorView dall'esempio che ho condiviso dovrebbe è la tua opinione che deve essere a schermo intero.non importa se si tratta di un frammento o di un'attività.puoi ottenere la vista corrente usando questo privilegio di codice.finestra Visualizza decorView = getWindow(). getDecorView(); –

3

Sono nuovo qui, quindi non posso commentare, ma ho voluto aggiungere qualcosa che mi ha così frustrato per la soluzione di cui sopra. Continuavo a controllare le mie attività e i suoi frammenti per android:fitsSystemWindows="true" e sicuramente non c'era, ma continuavo ad avere un buco in fondo! Stavo impazzendo! Non potrebbe essere così difficile risolvere questa semplice cosa!

Si scopre che è stato visualizzato anche nel Cassetto di navigazione che ho aggiunto ... quindi assicuratevi di controllare tutto il vostro XML!

Problemi correlati