android - fitSystemWindows 与 windowTranlucentStatus 和 windowTranslucentNavigation 使工具栏太高
问题描述
我试图让我的应用在状态栏和导航栏下流血。我使用 fitSystemWindows = true 使布局工作,只有状态栏是半透明的,但是当我也制作导航栏时,工具栏似乎会做出反应,就好像它需要在状态栏和通知栏下填充一样。 出于某种原因,工具栏在横向模式下似乎可以正常工作。 这种双“半透明”的条形效果也使得 NestedScrollView 延伸到了页面底部之外。我也不确定如何使 FAB 适合。
另一方面,我最初使用 CoordinatorLayout 编写布局。这增加了一个额外的问题,即 NestedScrollView 然后向上滚动到工具栏应位于的底部,而不是它所在的位置。但是,我认为 NestedScrollView 使用 CoordinatorLayout 正确尊重了底部屏幕边界。
这是布局的xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraint"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/toolbar">
<LinearLayout
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:clipToPadding="false"
android:orientation="vertical"
android:paddingBottom="74dp"/>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:background="@color/nav_color_1_bright"
android:elevation="4dp"
android:fitsSystemWindows="true"
app:navigationContentDescription="@string/open_nav_menu"
app:navigationIcon="@drawable/ic_dehaze_white_24dp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_margin="16dp"
android:clipToPadding="false"
android:fitsSystemWindows="true"
android:onClick="createNew"
android:src="@drawable/ic_add_black_24dp"
app:backgroundTint="@color/darkAccent"
app:fabSize="normal" />
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:itemBackground="@drawable/nav_item">
<ListView
android:id="@+id/drawer_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:dividerHeight="0dp"
android:fitsSystemWindows="true" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
我以编程方式将以下“轻主题”应用于活动。
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name ="android:windowTranslucentNavigation">true</item>
</style>
<style name="LightTheme" parent="AppTheme">
<item name="android:colorPrimary">@color/lightPrimary</item>
<item name="android:colorPrimaryDark">@color/lightPrimaryDark</item>
<item name="android:colorAccent">@color/lightAccent</item>
<item name="android:navigationBarColor">@color/lightPrimaryDark</item>
<item name="actionOverflowButtonStyle">@style/OverflowMenuButtonStyleDark</item>
</style>
这是布局的预览:(此处为大版本)
解决方案
推荐阅读
- python - 如何在 gitlab-ci.yml 中向 postgresql 数据库添加 postgis 扩展
- reactjs - Swagger-UI,反应应用程序 - 无法填充参数字段(或输入字段的数据未读取但已清除)
- python - 解码 base64 编码的图像会产生平面数组
- git - 如何从 git 用于登录的窗口中清除 ssh 密钥?
- php - 外部链接被阻止
- javascript - 无法通过淘汰赛和引导选择选择器获取下拉值
- json - app.use(express.json()) 给出意外的令牌错误
- scala - Spark Window 函数:是否可以直接从使用第一个/最后一个函数找到的行中获取其他值?
- android - 如何从谷歌地图扩展共享位置 URL?
- javascript - 将几个变量的值加一