简体   繁体   English

如何在标签中添加浮动操作按钮?

[英]How to add floating action button in tabs?

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. 我试图将fab添加到主要活动布局中,但是它被片段隐藏而不显示出来。 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? 您能否发布活动,以便我们跟踪您的代码并查看您的片段为何与操作按钮重叠?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM