9

事实上,我正在寻找一种模仿 FAB 收件箱的方法。当用户按下红色按钮时,应该会出现一个 opac 视图和一个菜单。因为图片更有意义,看下图

在此处输入图像描述

我知道它存在这个很棒的库(https://github.com/futuresimple/android-floating-action-button)并且有了这个库,我可以显示浮动操作菜单。但我的问题是显示白色背景(不透明)。我没有找到解决我的问题的方法......

提前谢谢

4

4 回答 4

17

FloatingActionMenu内部放置在FrameLayout其他视图之上,并将在宽度和高度上与父级匹配。使用相同的边距相应地从菜单右侧抬起和偏移。

设置OnFloatingActionsMenuUpdateListener为您的浮动操作菜单。现在在方法中切换/替换框架布局背景颜色:

 @Override
 void onMenuExpanded(){
  mFrameLayoutWrapper.setBackgroundColor(mAlpaWhite);
  }

  @Override
  void onMenuCollapsed(){
    mFrameLayoutWrapper.setBackgroundColor(Color.TRANSPARENT);
  }
于 2015-01-16T20:18:59.497 回答
0

我通过下面的方法达到了你刚才说的效果。我只是在浮动按钮后面和其他布局上方添加了一个视图,并保持视图可见性消失,直到菜单展开。然后我将视图可见性设置为可见。是的,我将视图的背景设置为您想要的任何不透明颜色。

我的代码

我的 XML 文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:text="Other View here"
    android:textSize="50dp"
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<View
    android:id="@+id/background_dimmer"
    android:visibility="gone"
    android:background="#55000000"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

<com.getbase.floatingactionbutton.FloatingActionsMenu
    android:id="@+id/multiple_actions"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    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.getbase.floatingactionbutton.FloatingActionButton
        android:id="@+id/action_a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_colorNormal="@color/white"
        fab:fab_title="Action A"
        fab:fab_colorPressed="@color/white_pressed"/>

</com.getbase.floatingactionbutton.FloatingActionsMenu>

在处理 FloatingButtons 的 Activity 或 Fragment

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);
    setFloatingButtonControls();
}

private void setFloatingButtonControls(){
    this.bckgroundDimmer = findViewById(R.id.background_dimmer);
    this.floatingActionsMenu = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
    this.floatingActionsMenu.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
        @Override
        public void onMenuExpanded() {
            bckgroundDimmer.setVisibility(View.VISIBLE);
        }

        @Override
        public void onMenuCollapsed() {
            bckgroundDimmer.setVisibility(View.GONE);
        }
    });
}

这将给出你想要的效果。希望这可以帮助。它确实帮助了我。:)

于 2015-10-05T17:24:53.023 回答
0

当我正确添加浮动时,它确实使我的组件移动到我想要的位置,但也得到了一个不必要的白色背景,但我可以通过在父 div 中引入“溢出:隐藏”来解决它。那应该可以解决问题

于 2021-04-03T20:21:02.753 回答
0

采用工具栏、浮动菜单、您的内容和相关布局的一种协调器布局。将相对布局的背景颜色设置为白色透明,并将其可见性设置为 Gone。设置“NoActionBar”主题并在活动中使用工具栏而不是操作栏。现在,每当您打开浮动菜单时,将相对布局的可见性设置为可见,关闭时设置回消失。

于 2016-05-27T12:34:58.183 回答