user5436545
user5436545

Reputation:

Add Navigation Drawer to Exsisting Andrdoid Google Map

I'm developing Android Google Map project.

Here is what i wanted.

Default screen is like this and when drawer page must like this

I already did the google map part and I created a new Navigation Drawer Activity. How Am I suppose to connect these 2? I mean, how can I set the screen under the navigation drawer to my map page?

Already tried,

@Override

public void onCreate(Bundle savedInstanceState){

super.onCreate(savedInstanceState);
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.content_frame, new Fragment1());
tx.commit();

}

Did not work.

Please help. This may be a silly question. but, I'm new to Andrdoid.

Thanks

-Edit - Here is the activity_maps.xml

<fragment 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:id="@+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />

Here is the activity_navigation.xml

<android.support.v4.widget.DrawerLayout
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:fitsSystemWindows="true">

<include layout="@layout/activity_maps"/>

<android.support.design.widget.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/drawer"/>

Here is the drawer_header.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="192dp"
    android:background="?attr/colorPrimaryDark"
    android:padding="16dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    android:orientation="vertical"
    android:gravity="bottom">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Abc"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>

</LinearLayout>

Here is the drawer.xml (menu)

    <?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">

    </group>

    <item android:title="Sub items">
        <menu>

        </menu>
    </item>

</menu>

I can not find what happened. But, I'm still getting the same error with this code.

Upvotes: 3

Views: 7286

Answers (1)

user5259714
user5259714

Reputation:

Follow these steps.

  1. Right click on your Android Studio project

  2. Select New-> Activity -> Navigation Drawer Activity

  3. Give a name and create the Navigation Drawer activity

  4. open activity_drawer.xml

  5. Add following code <include layout="@layout/activity_maps"/>

  6. You'll get your answer

Hope this will help. :)

Upvotes: 3

Related Questions