2016-03-15 45 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的常用工具栏。 –