I have a tabbed layout. So I have seven fragments. I want to add a floating action button on all fragments. So on all fragments there should only be on floating button.
I tried to add the fab in main activity layout, but it gets hidden by fragment it dose not show up. How can I achieve this?
I have used sliding tabs strips in this and sliding tabs layout.
Main activity layout :
<FrameLayout 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" tools:context="com.adgatemedia.offerwallsdk.fragments.MainFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<utils.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"
android:background="@color/colorPrimary"
android:layout_alignParentTop="true" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="@+id/tabs" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom|end">
<include layout="@layout/myfab"/>
</LinearLayout>
</RelativeLayout>
</FrameLayout>
Adapter:
public class TabsPagerAdapter extends FragmentPagerAdapter {
CharSequence Titles[];
int NumbOfTabs;
public TabsPagerAdapter(FragmentManager fm,CharSequence mTitles[], int mNumbOfTabsumb) {
super(fm);
this.Titles = mTitles;
this.NumbOfTabs = mNumbOfTabsumb;
}
@Override
public Fragment getItem(int index) {
switch (index) {
case 0:
return new Mon();
case 1:
return new Tue();
case 2:
return new Wed();
case 3:
return new Thu();
case 4:
return new Fri();
case 5:
return new Sat();
case 6:
return new Sun();
}
return null;
}
@Override
public CharSequence getPageTitle(int position) {
return Titles[position];
}
@Override
public int getCount() {
return NumbOfTabs;
}
}
Thank you..
Best way to achieve this is by adding the floating action button to tour activity. Can you post your activity so that we can trace your code and see why your fragments are overlapping your action button?