【发布时间】:2017-02-08 07:05:47
【问题描述】:
在一个活动中我有一个工具栏,它的布局代码是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.aminiam.moviekade.fragment.AllReviewFragment">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recReview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"/>
</LinearLayout>
我想在我的应用程序中有透明的状态栏,当我将<item name="android:windowTranslucentStatus">true</item> 添加到活动主题时,工具栏将与状态栏重叠。
values-v21 style.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.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:windowBackground">@color/windowBackground</item>
</style>
<style name="TransparentStatusBar" parent="AppTheme">
<item name="android:windowTranslucentStatus">true</item>
</style>
我在 Stackoverflow 中测试了所有答案,但都无法解决问题。
【问题讨论】:
-
AppBarLayout 主题应该是 `app:theme="@style/AppTheme.AppBarOverlay"` 并将其添加到样式
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />并在顶部线性布局中添加android:fitsSystemWindows="true" -
@AbhishekSingh Andorid 工作室说:找不到与给定名称匹配的资源(在“主题”处,值为“@style/AppTheme.AppBarOverlay”)。
-
我也只在评论中添加了你问题的答案
标签: android android-toolbar android-statusbar