0

I have a problem with Navigation View located under Toolbar. I've read that to set it up correctly apps should use Fragments instead of Activities, but unfortunately I think that it's not my case, coz the whole app is already written using Activities.

I could make NavView work nice in MainActivity (because toolbar is added in it's xml), but the problem is that I don't need NavView on start screen, only in specific activity.

Is it possible to add NavView to only one activity correctly without moving to Fragments?

MainActivity.xml (where it worked perfectly):

<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 (where I need to show 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>

Header layout:

    <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>

And a screenshot of how NavView in "aboutProduct" class looks now here

And how it should look like here

Cœur
  • 37,241
  • 25
  • 195
  • 267
asmodeoux
  • 389
  • 5
  • 14
  • yes, it is possible. What is the question? – Palak Darji Aug 24 '17 at 02:01
  • @PalakDarji then how? thank you in advance – asmodeoux Aug 24 '17 at 02:09
  • You've posted a SS which looks perfect. What's the problem exactly?. Also adding NavigationBar to any activity without fragment can be done by making a navigation activity and then displaying that very same NavigationBar to any activity. I've done that and it works fine but the question is what's the problem in that Screenshot?. – Lalit Fauzdar Aug 24 '17 at 02:32
  • @LalitSinghFauzdar unfortunately it's not perfect, it is covered by toolbar when added to another xmls but mainactivity. (I've added a ss of what I need in post) – asmodeoux Aug 24 '17 at 02:57
  • In `@layout/navigation_header`, Did you mean to put two TextView? – OneCricketeer Aug 24 '17 at 02:58
  • @cricket_007 only the bottom one, the upper is a part of toolbar which I dont wish to be visible :/ – asmodeoux Aug 24 '17 at 03:01
  • Can you please show that header layout? – OneCricketeer Aug 24 '17 at 03:02
  • @cricket_007 added to post – asmodeoux Aug 24 '17 at 03:16
  • What if you change `android:fitsSystemWindows` to be true? – OneCricketeer Aug 24 '17 at 03:22
  • @cricket_007 in that case it fills the screen, but still under toolbar: http://i.imgur.com/BhFE0S5.png – asmodeoux Aug 24 '17 at 03:31
  • I think the problem is that `@+id/include` is being laid out under the toolbar entirely. I might suggest trying LinearLayout instead of coordinatorlayout for the main activity – OneCricketeer Aug 24 '17 at 18:38
  • E.g. https://stackoverflow.com/a/26470144/2308683 ... https://stackoverflow.com/questions/26985270/navigation-drawer-below-toolbar ... https://stackoverflow.com/questions/34374382/navigation-drawer-behind-toolbar – OneCricketeer Aug 24 '17 at 18:41

1 Answers1

0

As a result I think that the easiest way is to set toolbar there in Theme Editor to "NoActionBar" and add toolbar to every activity by hands.

asmodeoux
  • 389
  • 5
  • 14