【发布时间】: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>
【问题讨论】:
-
这个问题你解决了吗?
-
我也有同样的问题。覆盖视图的 translationZ 部分解决了它(我仍然可以滚动覆盖层后面的视图),但它仅在 API v21 后才受支持
标签: android floating-action-button