在我的activity_navigation.xml
我把我的FAB
放在這裏。下面 的是:如何在所有活動中顯示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
而不重複添加我的xml
。 FAB
的所有行動我把它放在我的NavigationActivity
上。
謝謝你的幫助。
更新 通過我使用FrameLayout
命名content_frame
我的其他activities
以顯示Activity
喜歡的xml
在我Home Screen
這樣
FrameLayout contentFrameLayout = (FrameLayout) findViewById(R.id.content_frame);
getLayoutInflater().inflate(R.layout.activity_home, contentFrameLayout);
您的NavigationView具有匹配父級的高度。你框架佈局也高度匹配父母,他們將重疊,你嘗試設置你的框架佈局與20dp高度,並看到 – kggoh
@kggoh它仍然不顯示:(我試圖把20dp layout_height在framelayout。 – natsumiyu
@kggoh我試過把20dp高度放在我現在顯示的晶圓廠的其他活動xml中有沒有辦法解決這個問題?因爲我需要在屏幕上顯示整個活動的內容 – natsumiyu