2017-08-24 42 views
0

我有一個導航視圖位於工具欄下的一個問題。我已經閱讀過,爲了正確設置它,應用程序應該使用Fragments而不是Activities,但不幸的是,我認爲這不是我的情況,因爲整個應用程序已經使用Activities進行編寫。導航視圖中speciffic活動

我能NavView在MainActivity工作不錯(因爲添加工具欄在它的XML),但問題是,我不需要NavView開始屏幕上,只在特定的活動。

是否有可能NavView加起來也只有一個活動正確而不去碎片?

MainActivity.xml(它完美地工作):

<android.support.design.widget.CoordinatorLayout 
    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" 
    android:background="@drawable/bg" 
    tools:context="ru.asmodeoux.g_lounge.MainActivity"> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="59dp" 
     android:layout_height="59dp" 
     android:layout_gravity="top|left" 
     android:layout_margin="@dimen/fab_margin" 
     app:backgroundTint="@color/FAB_color" 
     app:elevation="24dp" 
     app:layout_anchor="@+id/include" 
     app:layout_anchorGravity="bottom|right" 
     app:srcCompat="@drawable/call" /> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="44dp" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:elevation="0dp" 
      android:minHeight="0dp" 
      android:textAlignment="center" 
      app:popupTheme="@style/AppTheme.AppBarOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <include 
     android:id="@+id/include" 
     layout="@layout/content_main" /> 
    </android.support.design.widget.CoordinatorLayout> 

aboutProduct.xml(在這裏我需要出示NavNiew):

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="false"> 


<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bg"> 


    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:background="@drawable/bg" 
       android:layout_height="match_parent"> 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:id="@+id/productRoot" 
        android:layout_height="wrap_content"> 

        <ImageView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_alignParentTop="true" 
         android:adjustViewBounds="true" 
         android:id="@+id/productImg" 
         /> 

        <TextView 
         android:id="@+id/productDescription" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_below="@id/productImg" 
         android:layout_marginBottom="75dp" 
         android:layout_marginTop="20dp" 
         android:paddingLeft="20dp" 
         android:paddingRight="20dp" 
         android:text="Place for product description." 
         android:textAlignment="textStart" 
         android:textColor="@color/white" 
         android:textSize="19sp" 
         android:textStyle="italic" /> 

       </RelativeLayout> 
      </ScrollView> 

      <android.support.design.widget.FloatingActionButton 
       android:id="@+id/productAdd" 
       android:layout_width="59dp" 
       android:layout_height="59dp" 
       android:layout_gravity="bottom|end" 
       android:layout_margin="@dimen/fab_margin" 
       android:backgroundTint="@color/FAB_color" 
       android:elevation="24dp" 
       app:srcCompat="@drawable/buy" /> 

      <TextView 
       android:id="@+id/productPrice" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom|start" 
       android:layout_marginBottom="@dimen/fab_margin" 
       android:background="@drawable/rectangle_rounded_some" 
       android:layout_marginLeft="@dimen/fab_margin" 
       android:paddingLeft="20dp" 
       android:paddingRight="20dp" 
       android:text="100 руб." 
       android:textAllCaps="false" 
       android:textColor="@color/black" 
       android:textSize="37sp" /> 



</android.support.design.widget.CoordinatorLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:layout_width="wrap_content" 
     app:headerLayout="@layout/navigation_header" 
     android:background="@color/white" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:menu="@menu/drawer" /> 


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

頭佈局:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/gray"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="70dp" 
     android:text="Что-то ещё?" 
     android:layout_marginStart="14dp" 
     android:textColor="@color/white" 
     android:textAlignment="textStart" 
     android:layout_marginBottom="8dp" 
     android:textSize="18sp" 
     android:textStyle="bold" /> 

</RelativeLayout> 

以及NavView在「aboutProduct」類中的截圖現在看起來如何here

以及應該如何看起來像here

+0

是的,這是可能的。什麼是問題? –

+0

@PalakDarji然後如何?預先感謝你 – asmodeoux

+0

你已經發布了一個看起來很完美的SS。那究竟是什麼問題?還可以將NavigationBar添加到沒有片段的任何活動中,方法是製作導航活動,然後將任何活動顯示爲相同的NavigationBar。我已經完成了,它的工作正常,但問題是該屏幕截圖中的問題是什麼? –

回答

0

因此,我認爲,最簡單的方法是設置工具欄上有在主題編輯器「NoActionBar」,並用手添加工具欄的每一次活動。