android 中的 19+ API 工具栏变得更大

ToolBar becomes so much bigger on 19+ API in android

我希望在我的应用程序中透明 StatusBar 以及 NavigationBar。因此我实现了这个使用:

values/style.xml

<style name="AppBaseTheme" parent="Theme.AppCompat">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
</style>

<style name="AppTheme" parent="AppBaseTheme"></style>


values-v19/style.xml

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>



但是,当它在 LollipopKitkat 设备上运行时, ToolBar 看起来比正常尺寸大得多。如何避免这种情况?
这是 ToolBar 代码。

<android.support.v7.widget.Toolbar
    android:id="@+id/tbHomeToolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="?attr/colorPrimary"
    android:fitsSystemWindows="true"
    android:minHeight="?attr/actionBarSize"
    app:navigationContentDescription="@string/app_name"
    app:navigationIcon="@drawable/ic_launcher" />


提前致谢

编辑
我改变了一些 属性 的 ToolBar

<android.support.v7.widget.Toolbar
    android:id="@+id/tbHomeToolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_alignParentTop="true"
    android:background="?attr/colorPrimary"
    android:fitsSystemWindows="true"
    app:navigationContentDescription="@string/app_name"
    app:navigationIcon="@drawable/ic_launcher" />


但是,情况变得更糟

编辑
我给出了我问题的部分答案。这可能有助于更多地了解我想要什么。

不要将 ?attr/actionBarSize 用于 minHeight 属性,而是将其用于 layout_height 属性,请参考以下代码。

<android.support.v7.widget.Toolbar
    android:id="@+id/tbHomeToolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_alignParentTop="true"
    android:background="?attr/colorPrimary"
    android:fitsSystemWindows="true"   
    app:navigationContentDescription="@string/app_name"
    app:navigationIcon="@drawable/ic_launcher" />

我给出了我自己的问题的答案,因为我没有找到我真正想要的解决方案。

解决方案一:
只需删除

<item name="android:windowTranslucentNavigation">true</item>

values-v19/styles.xml 开始,它工作得很好。
但是,这不是我想要的。

方案二:
也可以使用 FrameLayout 并使用 android:fitsSystemWindows="true"FrameLayout 而不是 ToolBar.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res/com.sparrow.chargeup"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:fitsSystemWindows="true"
    tools:context="com.sparrow.chargeup.HomeActivity" >

    <android.support.v7.widget.Toolbar
        android:id="@+id/tbHomeToolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        app:navigationContentDescription="@string/app_name"
        app:navigationIcon="@drawable/ic_launcher" />

</FrameLayout>

但是,它提供完全透明的 StatusBar 像这样

但是,我想要这样的透明导航



如果找不到确切答案,我会选择 Solution 2