android - 使用滚动工具栏隐藏状态栏
问题描述
当我在片段内滚动 RecyclerView 时,我想用工具栏隐藏状态栏。我现在只能隐藏工具栏。也许有人知道该怎么做?
之后: 我希望状态栏的不透明度为 0% 或 50% - 而不是图片中的 100%。
main_activity.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
tools:context=".main.MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/mainAppBarLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<androidx.appcompat.widget.Toolbar
android:id="@+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:elevation="4dp"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/app_name"
app:titleTextColor="@android:color/white"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/mainNav"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@android:color/white"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/user_tabs_menu" >
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:alpha="0.5"
android:background="@color/colorGray"
app:layout_constraintBottom_toTopOf="@+id/mainNav" />
</com.google.android.material.bottomnavigation.BottomNavigationView>
<FrameLayout
android:id="@+id/mainFrameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="55dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toTopOf="@+id/view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mainToolbar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我不想进行全屏活动 - 我希望导航栏可见。祝你今天过得愉快。
解决方案
像下面这样。不要忘记在工具栏中使用 app:layout_scrollFlags,为了更好地滚动,您可以使用 NestedScrollView
<android.support.design.widget.CoordinatorLayout
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
推荐阅读
- javascript - 为数组 html javascript 中的每个值创建新行
- docker - Docker 容器时区保持为 UTC
- excel - 计算超过 255 个字符的函数 - Excel/VBA
- pine-script - Pine Script v4 - 如何在前一根柱线的高点/低点设置止损?
- windows-machine-learning - 如何为具有未知组件的形状创建 TensorFloat?
- python - 如何从超像素和稀疏深度图估计深度?
- google-sheets - 数据透视表:如何按时间顺序对月份列进行排序
- java - Kotlin 中的 Java 类对象
- javascript - nodejs mariadb连接没有断开
- cytoscape.js - 用于紧凑显示的 cytoscape.js 树自动定位节点?