【问题标题】:Add Navigation Drawer to Exsisting Andrdoid Google Map将导航抽屉添加到现有的 Android 谷歌地图
【发布时间】:2016-01-21 15:57:06
【问题描述】:

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

这就是我想要的。

默认屏幕为 this,当抽屉页面必须为this

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

已经试过了,

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

我找不到发生了什么。但是,这段代码我仍然遇到同样的错误。

【问题讨论】:

  • 对不起。我知道如何添加导航抽屉活动。我需要更多。
  • 我认为你可以尝试在Android Design Support Library 中使用NavigationView。只需导入库并将&lt;android.support.design.widget.NavigationView 添加到您的布局中。更多详情请参考here
  • @bjiang,按照链接中的教程进行操作。没有帮助。你能看看编辑的部分吗?
  • 你需要创建的headerLayout,所以关于Android design support library的完整代码源请参考here。而this 是该样本中header_layout 的一部分。

标签: android google-maps navigation-drawer


【解决方案1】:

按照这些步骤操作。

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

  2. 选择新建->活动->导航抽屉活动

  3. 命名并创建导航抽屉活动

  4. 打开activity_drawer.xml

  5. 添加以下代码&lt;include layout="@layout/activity_maps"/&gt;

  6. 你会得到答案

希望这会有所帮助。 :)

【讨论】:

  • 非常感谢您的回答。像魅力一样工作
  • 是的想法很棒,还需要使用你的一些个人代码转移到相关的类。
猜你喜欢
  • 1970-01-01
  • 2016-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多