android - 将抽屉导航添加到现有的 Android 谷歌地图

标签 android google-maps navigation-drawer

我正在开发 Android 谷歌地图项目。

这就是我想要的。

默认屏幕类似于 this当抽屉页面必须喜欢 this

我已经完成了谷歌地图部分并创建了一个新的抽屉导航 Activity 。我应该如何连接这两个?我的意思是,如何将抽屉导航下的屏幕设置为我的 map 页面?

已经试过了,

@Override

public void onCreate(Bundle savedInstanceState){

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

没用。

请帮忙。这可能是一个愚蠢的问题。但是,我是 Andrdoid 的新手。

谢谢

-编辑- 这是 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" />

这是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"/>

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

这是drawer.xml(菜单)

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

我找不到发生了什么事。但是,我仍然遇到与此代码相同的错误。

最佳答案

按照以下步骤操作。

  1. 右键单击您的 Android Studio 项目

  2. 选择New->Activity->NavigationDrawerActivity

  3. 命名并创建 Navigation Drawer Activity

  4. 打开 activity_drawer.xml

  5. 添加以下代码 <include layout="@layout/activity_maps"/>

  6. 你会得到你的答案

希望这会有所帮助。 :)

关于android - 将抽屉导航添加到现有的 Android 谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33279886/

相关文章:

java - Android EditText动态高度以编程方式

android - DrawerLayout 的 item click - 什么时候替换 Fragment 合适?

Android - 如何将数据传递给runOnUiThread中的Runnable?

android - 闪屏中的闪屏出现在哪里?

android - 使用 FusedLocationApi 搜索地点

java - 如何在没有互联网的情况下在javascript中处理谷歌地图API

java - Android 抽屉导航图像

Android Navigation Drawer 没有通过拖动关闭它

java - 我收到以下运行时错误。请帮我找出原因

c# - 从 CSV 文件中提取数据(融合表和 kml 解决方法)