android 11 使用代码状态栏下拉后去掉设置按钮
时间: 2023-08-11 08:08:45 浏览: 51
如果你想在 Android 11 中使用代码的方式去掉状态栏下拉后的设置按钮,可以使用以下代码:
```java
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowInsetsController insetsController = getWindow().getInsetsController();
if (insetsController != null) {
insetsController.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
insetsController.hide(WindowInsets.Type.statusBars());
}
}
```
这段代码会获取当前窗口的`WindowInsetsController`对象,并通过调用`setSystemBarsAppearance()`方法去掉状态栏的亮色主题,然后调用`hide()`方法隐藏状态栏。
需要注意的是,这段代码只能在 Android 11 及以上的版本中使用,否则会导致程序崩溃。另外,这个方法只会在当前 Activity 中起作用,如果需要在整个应用中去掉状态栏下拉后的设置按钮,需要在所有的 Activity 中都添加这段代码。