2016-03-15 46 views
-1

我是Android設計的新人。我有Android Studio的Navigational DrawerLayout,當我的應用程序加載時,我正在爲應用程序加載初始Fragment用於Android Studio的導航抽屜主題的透明工具欄,帶有圖像重疊工具欄

  1. 我想使toolbar透明
  2. 我想具有被重疊DrawerLayout's toolbar
  3. 的圖像和用於其它Fragments我想同樣toolbar是不透明的。

第一屏時應用加載

enter image description here

當任何其它片段稱爲

enter image description here

+1

Andof當然你 「谷歌這幾個小時,但無法找到一個單一的文章」,對不對? –

+0

@Marcin Orlowski是的。 –

回答

0

對NO:1。

您只需要定義隱藏操作欄的主題,使用透明背景定義操作欄樣式並將此樣式設置爲工具欄小部件。請注意,工具欄應該drawen作爲最後一個視圖(所有視圖樹)

<style name="Theme.Custom" parent="@android:style/Theme.AppCompat"> 
    <item name="windowActionBar">false</item> 
    <item name="windowActionBarOverlay">true</item> 
    <item name="android:windowActionBarOverlay">true</item> 
</style> 

<style name="CustomActionBar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 
    <item name="android:windowActionBarOverlay">true</item> 
    <!-- Support library compatibility --> 
    <item name="windowActionBarOverlay">true</item> 
</style> 

佈局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- Toolbar should be above content--> 
    <include layout="@layout/toolbar" /> 

</RelativeLayout> 

工具欄佈局:

<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:theme="@style/CustomActionBar"/> 

對於無:2

將ImageView放在相對佈局中。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <!-- Toolbar should be above content--> 
     <include layout="@layout/toolbar" /> 


     <ImageView   
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:scaleType="centerInside" 
       android:adjustViewBounds="true" 
       android:transitionName="photo_hero" 
       android:id="@+id/image" 
       /> 
    </RelativeLayout> 

工具欄佈局:

<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:theme="@style/CustomActionBar"/> 
+0

謝謝你的解決方案,我會嘗試。我有一個基本問題,我是否必須在每個片段中使用工具欄?現在我有一個mainActivity的常用工具欄。 –