2014-10-30 5 views
7

Sto implementando il Material Design nella mia app che dispone di un cassetto di navigazione. Tra tutte le diverse implementazioni della Nav. Cassetto e barra degli strumenti con design del materiale (see this post); Ho scelto di mantenere l'applicazione simile al design ICS/Halo e far scorrere il Nav Drawer sotto la barra degli strumenti. Il problema è che la barra degli strumenti si attenua con l'ombra come il resto dell'attività quando il cassetto di navigazione è aperto. Come potrei mantenere la barra degli strumenti oscurata? Se vedi l'immagine nel post che ho linkato sopra, sono dopo # 6, 3 o 5, ma ora assomiglia più al n.Rimuovere l'ombra dalla barra degli strumenti quando il cassetto di navigazione è aperto - Libreria di supporto per la progettazione del materiale

Esempio (da post precedente):

Quello che sto cercando (senza ombra sulla barra degli strumenti):

enter image description here

Quello che attualmente ricevo (barra degli strumenti si oscura quando nav cassetto è aperto):

enter image description here

Ecco il codice per XML della mia attività principale:

012.351.
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.funkhaus.navdrawer.app.MainActivity"> 

<!-- As the main content view, the view below consumes the entire 
    space available using match_parent in both dimensions. --> 
<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- We use a Toolbar so that our drawer can be displayed 
     in front of the action bar; Added for Material Design --> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/my_awesome_toolbar" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:minHeight="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" /> 

    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="?attr/actionBarSize" /> 

</FrameLayout> 

<fragment android:id="@+id/navigation_drawer" 
    android:layout_width="@dimen/navigation_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_marginTop="?attr/actionBarSize" 
    android:fitsSystemWindows="true" 
    android:layout_gravity="start" 
    android:name="com.funkhaus.brewwerks.NavigationDrawerFragment" /> 

La parte notevole è che la <FrameLayout> cui ID è 'container' è dove tutti i miei frammenti sono gonfiati, e la sua marginTop è stato impostato per l'altezza della barra degli strumenti in modo il suo contenuto sarebbe al di sotto della barra degli strumenti. Analogamente, il frammento del Cassetto di navigazione ha anche il suo marginTop impostato all'altezza della barra degli strumenti in modo che scorra sotto di esso.

+1

Metti la barra degli strumenti fuori dal DrawerLayout. – alanv

+0

Dalla mia comprensione il '' deve essere la vista radice quando si utilizza il Navigation Navigationer – Flash

+1

La radice del contenuto, sì. Non la radice della tua barra degli strumenti. – alanv

risposta

9

Grazie a @alanv ho risolto il problema.

Il mio post in alto mostra il mio codice activity_main.xml; Ho semplificato a questa, la rimozione della barra degli strumenti Visualizza e la rimozione del marginTop formattazione:

<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:fitsSystemWindows="true" 
    tools:context="com.funkhaus.navdrawer.app.MainActivity"> 

<!-- As the main content view, the view below consumes the entire 
    space available using match_parent in both dimensions. --> 
    <FrameLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <fragment android:id="@+id/navigation_drawer" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     android:layout_gravity="start" 
     android:name="com.funkhaus.brewwerks.NavigationDrawerFragment" /> 

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

ho creato un toolbar.xml, che ora setContentView() nella mia attività principale che <include> s' il activity_main.xml sopra:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical"> 
    <!-- We use a Toolbar so that our drawer can be displayed 
      in front of the action bar; Added for Material Design --> 
    <android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/my_awesome_toolbar" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:minHeight="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" /> 

    <include android:id="@+id/drawer_layout" layout="@layout/activity_main" /> 

</LinearLayout> 

Infine, nella mia attività ho onCreate()setContentView() sul toolbar.xml:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.toolbar); 
    // Rest of code here.... 
+1

L'ActionBar è ancora supportato, perché non usarlo invece? Si comporta esattamente così. – CristianGuerrero

+1

Grazie mille! @ The Funk – theknut

+0

Anche se stiamo progettando consapevolmente il Navigation Drawer in base alle linee guida aggiornate sul material design, ecco un link a quelli aggiornati: http://www.google.com/design/spec/patterns/navigation-drawer. html – Flash

2
You do it in the same xml like this, This is for underlying toolbar navigation like play store app design 




    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context="com.ccas.roadsideconnect.BaseFragmentActivity"> 
    <android.support.v4.widget.DrawerLayout 

     android:id="@+id/drawer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 


     <FrameLayout 
      android:id="@+id/main_fragment_container" 
      android:layout_marginTop="?attr/actionBarSize" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 



     <FrameLayout android:id="@+id/navigation_drawer" 
      android:layout_width="@dimen/navigation_drawer_width" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      tools:layout="@layout/fragment_navigation_drawer" /> 
    </android.support.v4.widget.DrawerLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@drawable/img_actionbar_white_sm" 
       android:gravity="top" 
       android:minHeight="58.0dip" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
       /> 
     </LinearLayout> 

    </FrameLayout> 

Il seguente codice è per la navigazione della barra degli strumenti sovrastante come Gmail APP design.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.ccas.roadsideconnect.BaseFragmentActivity"> 
<android.support.v4.widget.DrawerLayout 

    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

    <FrameLayout 
     android:id="@+id/main_fragment_container" 
     android:layout_marginTop="?attr/actionBarSize" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@drawable/img_actionbar_white_sm" 
      android:gravity="top" 
      android:minHeight="58.0dip" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      app:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
      /> 
    </LinearLayout> 

    <FrameLayout android:id="@+id/navigation_drawer" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     tools:layout="@layout/fragment_navigation_drawer" /> 
</android.support.v4.widget.DrawerLayout> 

</FrameLayout> 
Problemi correlati