Reputation:
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
Reputation:
Follow these steps.
Right click on your Android Studio project
Select New-> Activity -> Navigation Drawer Activity
Give a name and create the Navigation Drawer activity
open activity_drawer.xml
Add following code <include layout="@layout/activity_maps"/>
You'll get your answer
Hope this will help. :)
Upvotes: 3