<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] ![](https://img.kancloud.cn/f1/4c/f14cb32859275a89010cec94f29468e5_264x475.png) # 設置狀態欄和導航欄 UI Flag名稱|作用|說明 ---|---|--- View.SYSTEM\_UI\_FLAG\_FULLSCREEN|隱藏狀態欄|一般同時隱藏ActionBar View.SYSTEM\_UI\_FLAG\_LAYOUT\_FULLSCREEN和View.SYSTEM\_UI\_FLAG\_LAYOUT\_STABLE|應用主體內容占用狀態欄(用于更改狀態欄顏色)|兩個Flag必須同時使用,然后調用Window的setStatusBarColor()方法 View.SYSTEM\_UI\_FLAG\_HIDE\_NAVIGATION|隱藏導航欄| View.SYSTEM\_UI\_FLAG\_LAYOUT\_HIDE\_NAVIGATION和View.SYSTEM\_UI\_FLAG\_LAYOUT\_STABLE|應用主體內容占用導航欄(用于更改導航欄顏色)|兩個Flag必須同時使用,然后調用Window的setNavigationBarColor()方法 ## 隱藏狀態欄 ```java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View decorView = getWindow().getDecorView(); // 隱藏狀態欄 int option = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(option); // 隱藏ActionBar ActionBar actionBar = getSupportActionBar(); actionBar.hide(); } } ``` ## 設置狀態欄顏色 ```java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= 21) { View decorView = getWindow().getDecorView(); int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; decorView.setSystemUiVisibility(option); // 此處設置為透明狀態欄,也可設置為其他顏色 getWindow().setStatusBarColor(Color.TRANSPARENT); } // 隱藏ActionBar ActionBar actionBar = getSupportActionBar(); actionBar.hide(); } } ``` ## 隱藏導航欄 ```java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View decorView = getWindow().getDecorView(); // 隱藏導航欄 int option = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; decorView.setSystemUiVisibility(option); } } ``` ## 設置導航欄顏色 ```java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= 21) { View decorView = getWindow().getDecorView(); int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; decorView.setSystemUiVisibility(option); // 此處設置為透明導航欄,也可設置為其他顏色 getWindow().setNavigationBarColor(Color.TRANSPARENT); } } } ``` # 沉浸式模式 ![](https://img-blog.csdn.net/20160820202910617) ```java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus && Build.VERSION.SDK_INT >= 19) { View decorView = getWindow().getDecorView(); 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 | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } } } ``` # 劉海屏適配 ## 設置應用內容延伸到劉海區 屬性名稱|作用|說明 ---|---|--- LAYOUT\_IN\_DISPLAY\_CUTOUT\_MODE\_DEFAULT|默認屬性,應用的內容在豎屏模式下自動延伸到劉海區域,在橫屏模式下則不會延伸到劉海區域|在小米9上測試此屬性在豎屏模式下也不會延伸到劉海區 LAYOUT\_IN\_DISPLAY\_CUTOUT\_MODE\_SHORT\_EDGES|不管手機處于橫屏還是豎屏模式,都會允許應用程序的內容延伸到劉海區域 LAYOUT\_IN\_DISPLAY\_CUTOUT\_MODE\_NEVER|永遠不允許應用程序的內容延伸到劉海區域 ```java public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 這里需要調用這兩行代碼,來去除旋轉屏幕時狀態欄出現的問題 requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.hide(); } if (Build.VERSION.SDK_INT >= 28) { WindowManager.LayoutParams params = getWindow().getAttributes(); params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; getWindow().setAttributes(params); } } @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus && Build.VERSION.SDK_INT >= 19) { View decorView = getWindow().getDecorView(); 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 | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } } } ``` ## 獲取安全顯示區域 獲取安全顯示區域的偏移量,再設置給控件即可。 ```java rootLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @Override public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) { DisplayCutout displayCutout = windowInsets.getDisplayCutout(); if (displayCutout != null) { int left = displayCutout.getSafeInsetLeft(); int top = displayCutout.getSafeInsetTop(); int right = displayCutout.getSafeInsetRight(); int bottom = displayCutout.getSafeInsetBottom(); ConstraintLayout.LayoutParams topParams = (ConstraintLayout.LayoutParams) topButton.getLayoutParams(); topParams.setMargins(left, top, right, bottom); ConstraintLayout.LayoutParams leftParams = (ConstraintLayout.LayoutParams) leftButton.getLayoutParams(); leftParams.setMargins(left, top, right, bottom); } return windowInsets.consumeSystemWindowInsets(); } }); ``` 參考文檔: [Android狀態欄微技巧,帶你真正理解沉浸式模式](https://blog.csdn.net/guolin_blog/article/details/51763825) [Android 9.0系統新特性,對劉海屏設備進行適配](https://blog.csdn.net/guolin_blog/article/details/103112795)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看