Решение
Мне удалось получить то, что я хотел! Я думал, что это будет легче получить, однако, я пишу свое решение на случай, если оно будет полезным, и если кто-то захочет улучшить его!
Когда пользователь не выполняет прокрутку, высота панели инструментов равна 0. ![enter image description here](https://i.stack.imgur.com/xPF3g.jpg)
Когда пользователь выполняет прокрутку, высота панели инструментов изменяется и вся панель инструментов и строка состояния ( уведомление строка состояния) прозрачны!
![enter image description here](https://i.stack.imgur.com/n2rYu.jpg)
Как выглядит мой? ![enter image description here](https://i.stack.imgur.com/bDUty.jpg)
![enter image description here](https://i.stack.imgur.com/LwvsV.jpg)
Давайте создадим CoordinatorLayout с помощью панели инструментов, NestedScrollView и LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:background="@color/colorPrimary">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorToolbar"
android:elevation="0dp"
app:titleTextColor="@color/colorTextMain"
android:fitsSystemWindows="true"/>
<androidx.core.widget.NestedScrollView
android:id="@+id/myScroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
... place page content here ...
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Теперь внутри вашего класса OnCreate метод
// find the toolbar view inside the activity layout
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitleTextAppearance(this, R.style.FontStyle);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle(getString(R.string.about));
toolbar.setElevation(1); // required or it will overlap linear layout
toolbar.setBackgroundColor(Color.TRANSPARENT); // required to delete elevation shadow
// status bar height programmatically , notches...
statusBarHeight = getStatusBarHeight();
linearLayout = findViewById(R.id.linear_layout);
linearLayout.setPadding(1,180+statusBarHeight,1,0);
ViewGroup.LayoutParams params = toolbar.getLayoutParams();
params.height = 180+statusBarHeight;
toolbar.setLayoutParams(params);
Поскольку у нас есть метки (:-(), мы должны вычислить высоту строки состояния программно. По умолчанию высота строки состояния равна 24dp. К сожалению, не все модели Notch используют 24dp. Как программно рассчитать высоту строки состояния
Теперь нам нужно обрабатывать высоту панели инструментов независимо от того, перемещается пользователь по странице или нет. Внутри вашего класса OnCreate метод
NestedScrollView scroller = findViewById(R.id.myScroll);
scroller.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
if (scrollY > oldScrollY) {
// when user scrolls down set toolbar elevation to 4dp
toolbar.setElevation(4);
toolbar.setBackgroundColor(getColor(R.color.colorToolbar));
}
if (scrollY < oldScrollY) {
// when user scrolls up keep toolbar elevation at 4dp
toolbar.setElevation(4);
toolbar.setBackgroundColor(getColor(R.color.colorToolbar));
}
if (scrollY == 0) {
// if user is not scrolling it means
// that he is at top of page
toolbar.setElevation(1); // required or it will overlap linear layout
toolbar.setBackgroundColor(Color.TRANSPARENT); // required to delete elevation shadow
}
});
Почти готово! Это важная часть! Опять внутри вашего класса OnCreate метод
switch (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
case Configuration.UI_MODE_NIGHT_YES:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().setStatusBarColor(Color.TRANSPARENT);
break;
case Configuration.UI_MODE_NIGHT_NO:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
getWindow().setStatusBarColor(Color.TRANSPARENT);
break;
}
Configuration.UI_MODE_NIGHT_YES и Configuration.UI_MODE_NIGHT_NO: способ обработки темных и светлых тем. Поскольку мы собираемся поместить все содержимое страницы в строку состояния, мы больше не будем контролировать значки строки состояния. C olors (можно получить с помощью стилей), поэтому нам нужно определить, включена ли светлая или темная тема для программно установленных цветов значков строки состояния!