【问题标题】:FAB (Floating Action Button) Overlay in lollipop and higher version棒棒糖和更高版本中的 FAB(浮动操作按钮)覆盖
【发布时间】:2016-05-30 15:48:47
【问题描述】:

我正在开发一个使用FloatingActionButton(FAB) 的应用程序,就像Skype 或收件箱一样。 FAB 的 onClick 我正在显示带有叠加背景的对话框。

对于 Kitkat 版本,将覆盖整个屏幕,这很好,但对于棒棒糖和棉花糖,它只覆盖到 PageViewer 并且它不覆盖 ActionBar(AppBarLayout)。我正在尝试修复它,但我做不到。

我该如何解决这个问题?

这里是sn-p的代码:

    final FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frame_layout);
    frameLayout.getBackground().setAlpha(0);
    final FloatingActionsMenu fabMenu = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
    fabMenu.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
        @Override
        public void onMenuExpanded() {
           frameLayout.getBackground().setAlpha(240);
            frameLayout.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    fabMenu.collapse();
                    return false;
                }
            });
        }

        @Override
        public void onMenuCollapsed() {
            frameLayout.getBackground().setAlpha(0);
            frameLayout.setOnTouchListener(null);
        }
    });`

这是布局:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppThemeBlue">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:titleTextColor="@color/white"
        app:popupTheme="@style/AppThemeBlue"
        app:layout_scrollFlags="scroll|enterAlways|snap" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabTextColor="@android:color/white"
        app:tabSelectedTextColor="@android:color/white"
        app:tabIndicatorColor="@android:color/white"
        app:tabIndicatorHeight="3dp"/>

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<FrameLayout
    android:id="@+id/frame_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white_overlay"
    android:layout_gravity="bottom|end">

<com.support.android.fabbutton.FloatingActionsMenu
        xmlns:fab="http://schemas.android.com/apk/res-auto"
        android:id="@+id/multiple_actions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        fab:fab_addButtonColorNormal="@color/white"
        fab:fab_addButtonColorPressed="@color/white_pressed"
        fab:fab_addButtonPlusIconColor="@color/half_black"
        fab:fab_labelStyle="@style/menu_labels_style"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginEnd="16dp">

        <com.support.android.fabbutton.FloatingActionButton
            android:id="@+id/action_a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_icon="@drawable/micro"
            fab:fab_size="mini"
            fab:fab_colorNormal="@color/white"
            fab:fab_title="Action A"
            fab:fab_colorPressed="@color/white_pressed" />

        <com.support.android.fabbutton.FloatingActionButton
            android:id="@+id/action_b"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_size="mini"
            fab:fab_colorNormal="@color/white"
            fab:fab_title="Action with a very long name "
            fab:fab_colorPressed="@color/white_pressed"/>

    </com.support.android.fabbutton.FloatingActionsMenu>
</FrameLayout>

这是我目前正在实现的目标。如您所见,ActionBar 未被覆盖...

【问题讨论】:

  • 这个问题你解决了吗?
  • 我也有同样的问题。覆盖视图的 translationZ 部分解决了它(我仍然可以滚动覆盖层后面的视图),但它仅在 API v21 后才受支持

标签: android floating-action-button


【解决方案1】:

您已经用框架布局包装了您的工厂并将其放置在 viewpager 内,因此它只会显示在 viewpager 内...将您的 xml 包装在协调器布局中,然后检查它是否正常工作..将框架布局移出视图寻呼机

喜欢这个

<android.support.design.widget.CoordinatorLayout
        android:id="@+id/root_coordinator"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppThemeBlue">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:titleTextColor="@color/white"
        app:popupTheme="@style/AppThemeBlue"
        app:layout_scrollFlags="scroll|enterAlways|snap" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabTextColor="@android:color/white"
        app:tabSelectedTextColor="@android:color/white"
        app:tabIndicatorColor="@android:color/white"
        app:tabIndicatorHeight="3dp"/>

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


<com.support.android.fabbutton.FloatingActionsMenu
        xmlns:fab="http://schemas.android.com/apk/res-auto"
        android:id="@+id/multiple_actions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        fab:fab_addButtonColorNormal="@color/white"
        fab:fab_addButtonColorPressed="@color/white_pressed"
        fab:fab_addButtonPlusIconColor="@color/half_black"
        fab:fab_labelStyle="@style/menu_labels_style"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginEnd="16dp">

        <com.support.android.fabbutton.FloatingActionButton
            android:id="@+id/action_a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_icon="@drawable/micro"
            fab:fab_size="mini"
            fab:fab_colorNormal="@color/white"
            fab:fab_title="Action A"
            fab:fab_colorPressed="@color/white_pressed" />

        <com.support.android.fabbutton.FloatingActionButton
            android:id="@+id/action_b"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_size="mini"
            fab:fab_colorNormal="@color/white"
            fab:fab_title="Action with a very long name "
            fab:fab_colorPressed="@color/white_pressed"/>

    </com.support.android.fabbutton.FloatingActionsMenu>

    </android.support.design.widget.CoordinatorLayout>

【讨论】:

  • 如果框架布局是问题,那么它如何在 kitkat 中正常工作?并且还尝试删除它..但它没有工作..
  • 框架布局不是问题,你可以保留它,但使用内部协调器布局..检查我发布的 xml。你试过了吗?
  • 我的意思是说您的 alpha 将仅应用于 viewpager 内的 framelayout ..上述两个 appbar 和 tablayout 被排除在外.. 在您的情况下更改 root (appbarlayout) 的 alpha 或更改 alpha在我的情况下的坐标布局,所以你会得到想要的效果
猜你喜欢
  • 2016-02-03
  • 1970-01-01
  • 1970-01-01
  • 2015-12-13
  • 1970-01-01
  • 2015-02-26
  • 2015-08-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多