-2

In my placeOrder activity navigation drawer is not starting from the top side of device screen as you can see in the scrrenshot of emulator.

this is my xml file in which i have implemented navigation drawer.

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


<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/nav_container"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/container"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            >

            <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/t_placeorder"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <TableRow>
                    <TextView
                        android:id="@+id/tv_psize"
                        android:text="@string/p_size"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_column="1"
                        />

                    <Spinner
                        android:layout_width="200dp"
                        android:layout_height="wrap_content"
                        android:id="@+id/size"
                        android:entries="@array/paper_size"
                        android:layout_marginTop="20dp"
                        android:layout_marginLeft="20dp"
                        android:spinnerMode="dropdown"
                        android:layout_column="1" />
                </TableRow>

                <TableRow>
                    <TextView
                        android:id="@+id/tv_pcolor"
                        android:layout_width="wrap_content"
                        android:text="@string/p_color"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_column="1"
                        />
                    <Spinner
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:entries="@array/color"
                        android:id="@+id/color"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"></Spinner>
                </TableRow>

                <TableRow>
                    <TextView
                        android:id="@+id/tv_pbinding"
                        android:layout_width="wrap_content"
                        android:text="@string/p_binding"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"

                        android:layout_column="1"/>
                    <Spinner
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/binding"
                        android:entries="@array/binding"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"

                        ></Spinner>
                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/tv_ptype"
                        android:layout_width="wrap_content"
                        android:text="@string/p_type"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_column="1"/>
                    <Spinner
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/type"
                        android:entries="@array/type"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"
                        ></Spinner>
                </TableRow>

                <TableRow>
                    <TextView
                        android:id="@+id/tv_pattach"
                        android:layout_width="wrap_content"
                        android:text="@string/p_attach"
                        android:layout_height="wrap_content"
                        android:layout_column="1"
                        android:layout_marginTop="20dp"
                        />

                    <Button
                        android:id="@+id/b_browse"
                        android:layout_width="wrap_content"
                        android:layout_height="40dp"
                        android:background="@color/colorPrimary"
                        android:textColor="@color/white"
                        android:text="@string/b_browse"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"
                        />
                </TableRow>
                <TableRow>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/selected"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"
                        android:id="@+id/file_path"
                        android:text="@string/file_path"
                        android:layout_column="2"
                        />

                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/tv_pncpoies"
                        android:layout_width="wrap_content"
                        android:text="@string/p_copies"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_column="1"
                        />
                    <EditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/et_ncpoies"
                        android:hint="@string/p_ncopies"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:layout_marginTop="20dp"
                        />
                </TableRow>
                <TableRow>
                    <TextView
                        android:id="@+id/tv_ppgnum"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/pgnum"
                        android:layout_marginTop="20dp"
                        android:layout_column="1"
                        />
                    <RadioGroup
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:orientation="vertical"
                        android:id="@+id/radiogroup1"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"

                        >
                        <RadioButton
                            android:text="@string/Poption1"
                            android:id="@+id/rb_poption1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            />
                        <RadioButton
                            android:text="@string/poption2"
                            android:id="@+id/rb_poption2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            />
                    </RadioGroup>

                </TableRow>
                <TableRow>
                    <EditText
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/custom_print"
                        android:hint="1-30,50,55,60-90,100"
                        android:layout_column="2"
                        android:layout_marginLeft="20dp"
                        android:visibility="invisible"
                        />



                </TableRow>
            </TableLayout>

            <RadioGroup
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/t_placeorder"
                android:layout_marginTop="20dp"
                android:orientation="horizontal"
                android:id="@+id/radiogroup">
                <RadioButton
                    android:text="@string/p_homed"
                    android:id="@+id/rb_home"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="onRadioButtonClicked"/>
                <RadioButton
                    android:text="@string/pickup"
                    android:id="@+id/rb_pick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="onRadioButtonClicked"
                    android:layout_marginLeft="50dp"
                    />
            </RadioGroup>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/address"
                android:orientation="vertical"
                android:layout_marginTop="20dp"
                android:layout_below="@+id/radiogroup"
                >

            </LinearLayout>

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/b_proceed"
                android:id="@+id/b_proceed"
                android:layout_below="@id/address"
                android:layout_marginTop="20dp"
                android:background="@color/colorPrimary"
                android:textColor="@color/white"
                android:onClick="OnOrder"


                />


        </RelativeLayout>

    </ScrollView>


</FrameLayout>
<android.support.design.widget.NavigationView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:menu="@menu/nav_menu"
    android:id="@+id/navigatiom_view"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"/>

2 Answers2

2

You need to make DrawerLayout as parent..Try this way it will help you

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

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

http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
0

New App Compat library support this feature all you need to do is use toolbar instead of Action bar its more customizable than action bar and relatively easy to use than Action bar.

Add this to your styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="dialogTheme">@style/Theme.Dialog</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark" />

Apply this theme to your App in manifest.xml

<application
    ....
    ....
    android:theme="@style/AppTheme">

Now create your layout like this

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:tools="http://schemas.android.com/tools"
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.support.v4.widget.DrawerLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout"
    tools:openDrawer="start">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/myAppBar"
            android:theme="@style/AppTheme.AppBarOverlay">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay"
                app:title="Jewellery"/>
        </android.support.design.widget.AppBarLayout>

        <!--Your Layout Here-->
        <RelativeLayout 
            android:id="@+id/main_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/tabs"
                android:id="@+id/scroll"
                android:scrollbars="none">
                <FrameLayout
                    android:id="@+id/container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                </FrameLayout>
            </ScrollView>
        </RelativeLayout>
        <!-----Layout Ends-->

    </LinearLayout>

      <android.support.design.widget.NavigationView
          android:id="@+id/nav_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:fitsSystemWindows="true"
          app:headerLayout="@layout/nav_header"/>
   </android.support.v4.widget.DrawerLayout>
</android.support.design.widget.CoordinatorLayout>

Now in your Main Activity

Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if(getSupportActionBar()!=null){
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close);
mDrawerLayout.addDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
Abhishek Singh
  • 9,008
  • 5
  • 28
  • 53