2015-12-22 4 views
13

दिखा, लेकिन Android 4.4 और बाद के लिए, यह वहाँ एक रिक्त स्थान पता चलता है:इमर्सिव मोड मैं एक पूर्ण स्क्रीन मोड को लागू करने की कोशिश कर रहा हूँ रिक्त स्थान

इमर्सिव मोड (फुलस्क्रीन)

enter image description here

पहले

और toggleFullScreen (झूठी) के बाद;

enter image description here

के रूप में आप देख सकते हैं, अपनी यह को दूर नहीं है।

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

क्या आपको इसके लिए समाधान मिला। मुझे एक ही समस्या का सामना करना पड़ रहा है – glo

+0

@glo नीचे दिया गया समाधान मेरे लिए काम कर रहा है। जांचें [यह] (https://gitlab.com/ankit_aggarwal/ToggleFullScreenDemo.git) कोड –

+0

@glo यह एंड्रॉइड एल और केवल ऊपर या निम्न संस्करणों के लिए भी हो रहा है? यदि हां, तो क्या यह केवल स्थिति या नीचे नेविगेशन बार के साथ हो रहा है? –

उत्तर

24

है जैसे कि यह प्रयास करें कृपया जांच करें कि आप अपने लेआउट में android:fitsSystemWindows="true" जरूरत नहीं है।

कम से कम यह मेरे मामले को हल करता है - मैं फ़्रेमलाइट पर सिस्टमविंडोज फिट बैठता था।

0

आप अपने दृश्य View.SYSTEM_UI_FLAG_LAYOUT_STABLE को यह ध्वज जोड़ने की जरूरत है: यहाँ कोड है कि मैं इसे चालू करने के लिए उपयोग कर रहा हूँ है। इस

// 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

हाय @android_Muncher, यह हल नहीं हुआ, = (, मैं फ्रैगमेंट का उपयोग कर रहा हूं लेकिन गतिविधि से टॉगलफ्लस्क्रीन को कॉल कर रहा हूं, फिर भी एक ग्रे स्पेस दिखाता हूं जहां मुलायम बटन थे और एक काला स्थान जहां अधिसूचना बार – user2582318

+0

mDecorView था जिसे मैंने साझा किया था अपने विचार को देखें कि पूर्ण स्क्रीन होने की आवश्यकता है। इससे कोई फर्क नहीं पड़ता कि यह एक टुकड़ा या गतिविधि है। आप कोड के इस ग्रह का उपयोग करके वर्तमान दृश्य प्राप्त कर सकते हैं। अंतिम देखें decorView = getWindow()। getDecorView(); getDecorView(); –

3

मैं यहां नया हूं इसलिए मैं टिप्पणी नहीं कर सकता, लेकिन कुछ ऐसा जोड़ना चाहता था जिसने मुझे उपरोक्त समाधान के बारे में मुझे इतना निराश किया। मैंने अपनी गतिविधियों और इसके टुकड़े android:fitsSystemWindows="true" के लिए जांचते रहे और यह निश्चित रूप से वहां नहीं था, फिर भी मैंने नीचे एक अंतर रखा है! मैं पागल हो रहा था! इस साधारण चीज़ को ठीक करना मुश्किल नहीं हो सकता!

बाहर निकलता है यह नेविगेशन ड्रॉवर में भी दिखाया गया है ... इसलिए अपने सभी एक्सएमएल को जांचना सुनिश्चित करें!

संबंधित मुद्दे