如何在所有活动中显示FAB

How to display the FAB in all activities

在我的 activity_navigation.xml 中,我把我的 FAB 放在这里。 如下:

<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"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

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

    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:menu_icon="@drawable/quick_apply"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="8dp"
        android:layout_marginRight="8dp">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/view_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/imgicon"
            fab:fab_size="mini"
            fab:fab_label="View Images" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/camera"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/camicon"
            fab:fab_size="mini"
            fab:fab_label="Camera" />

    </com.github.clans.fab.FloatingActionMenu>

</FrameLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigationView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:menu="@menu/activity_navigation_drawer"
    android:background="@color/tableHeader"/>

我在我的 NavigationActivity 上设置了这个 xml,就像我的 BaseActivity 一样,然后将它扩展到我的所有其他 Activities

我的问题是 运行 应用 FAB 没有显示,因为它已被我分配给 content_frame 的 xml 覆盖。但是,如果我将 com.github.clans.fab.FloatingActionMenu 放在我的另一个 activities's xml 中,例如在我的 Home Screen 中,它会显示它,但我想知道如何显示 FAB 而不重复它添加我的 xmlFAB的所有动作我都放在我的NavigationActivity上了。

感谢您的帮助。

更新 顺便说一下,我正在使用名为 content_frameFrameLayout 来显示另一个 activitiesxml,就像在我的 Home Screen 中一样像这样

FrameLayout contentFrameLayout = (FrameLayout) findViewById(R.id.content_frame);
    getLayoutInflater().inflate(R.layout.activity_home, contentFrameLayout);  

//我没有你的资源值,所以我尝试做一个测试例子,用textview替换你的抽屉视图。如果我将 framelayout 高度与父级匹配,我只会看到一个文本视图,只有当我将高度设置为 20dp 时,它才会出现两个文本视图。

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="20dp"
            android:id="@+id/content_frame">

            <TextView
                android:text="text above"
                android:textSize="20sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </FrameLayout>


        <TextView
            android:text="text below"
            android:textSize="20sp"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

    </LinearLayout>

我所做的是在 activity_navigation.xml

中创建两个 FrameLayout
 <FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>

<com.github.clans.fab.FloatingActionMenu
    android:id="@+id/menu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    fab:menu_icon="@drawable/quick_apply"
    android:layout_gravity="bottom|right"
    android:layout_marginBottom="8dp"
    android:layout_marginRight="8dp">

    <com.github.clans.fab.FloatingActionButton
        android:id="@+id/view_img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/imgicon"
        fab:fab_size="mini"
        fab:fab_label="View Images" />

    <com.github.clans.fab.FloatingActionButton
        android:id="@+id/camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/camicon"
        fab:fab_size="mini"
        fab:fab_label="Camera" />

</com.github.clans.fab.FloatingActionMenu>

</FrameLayout>

我的FAB不在content_frame里面,这样就不会重叠了。

使用Activity的片段瞬间