2015-04-27 61 views
0

我想讓我的工具欄/操作欄透明。我可以看到一個透明的工具欄,但隱藏在片段加載的小部件後面。該小部件是圖像的輪播。所以當圖像翻轉時,我可以看到它下面的工具欄。這是我的應用主題。Android AppCompat覆蓋工具欄隱藏在部件後

<style name="AppTheme" parent="@style/Theme.AppCompat.Light"> 
    <item name="colorPrimary">#19b333</item> 
    <!-- ActionBar Theming --> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 

    <!-- Support library compatibility --> 
    <item name="actionBarStyle">@style/MyActionBar</item> 
</style> 

這是我的ActionBar主題。

<style name="MyActionBar" parent="ThemeOverlay.AppCompat.Light"> 
    <item name="android:background">@color/color_primary</item> 
    <item name="android:windowActionBarOverlay">true</item> 

    <!-- Support library compatibility --> 
    <item name="background">@color/color_primary</item> 
    <item name="windowActionBarOverlay">true</item> 
</style> 

這是我的工具欄:

<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_height="wrap_content" 
    android:layout_width="match_parent" 
    android:minHeight="?attr/actionBarSize"/> 

這是我activity_drawer佈局

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout" 
    tools:context=".activity.DrawerActivity"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <include layout="@layout/view_toolbar"/> 

     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </RelativeLayout> 

    <fragment 
     android:name="com.example.fragment.SidebarFragment" 
     android:id="@+id/sidebar" 
     android:layout_width="@dimen/sidebar_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     tools:layout="@layout/fragment_sidebar" /> 

</android.support.v4.widget.DrawerLayout> 

回答

2

把工具欄內容容器後。

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <include layout="@layout/view_toolbar"/> 

</RelativeLayout>