0

我正在使用以下 FAB 库
https://github.com/futuresimple/android-floating-action-button
并按照这个stackoverflow发布浮动操作按钮和白色背景以在屏幕上显示覆盖。

我使用上面提到的帖子在 Fragment 中使用 FloatingActionButton,但覆盖不会超过操作栏。找不到任何解决方案来全屏显示覆盖(包括操作栏)

代码片段.java

final FrameLayout fl =    FrameLayout)view.findViewById(R.id.floatingcontainer);        
final FloatingActionsMenu fam = (FloatingActionsMenu) fl.findViewById(R.id.multiple_actions);       

fam.setOnFloatingActionsMenuUpdateListener(new OnFloatingActionsMenuUpdateListener() {

        @Override
        public void onMenuExpanded() {
            // TODO Auto-generated method stub
            fl.setBackgroundColor(Color.parseColor("#c0ffffff"));               

        }

        @Override
        public void onMenuCollapsed() {
            // TODO Auto-generated method stub  
            fl.setBackgroundColor(Color.TRANSPARENT);               
        }
    });


    fl.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // ignore all touch events
            if(fam.isExpanded()){
                fam.collapse();
                return true;
            }
            return false;
        }
    });

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/com.yourapp.data"    
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">

//some previous code

<FrameLayout android:layout_width="match_parent"
    android:layout_height="match_parent"    
    android:id="@+id/floatingcontainer"   
    android:clickable="false" >

    <com.getbase.floatingactionbutton.FloatingActionsMenu
        android:id="@+id/multiple_actions"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="66dp"        
        fab:fab_addButtonColorNormal="@color/orange"
        fab:fab_addButtonColorPressed="@color/orange_pressed"           
        fab:fab_labelStyle="@style/menu_labels_style" >

        <com.getbase.floatingactionbutton.FloatingActionButton
            android:id="@+id/action_a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_icon="@drawable/menu1"
            fab:fab_colorNormal="@color/orange"
            fab:fab_colorPressed="@color/orange_pressed"
            fab:fab_title="Menu 1" />

        <com.getbase.floatingactionbutton.FloatingActionButton
            android:id="@+id/action_b"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_icon="@drawable/menu2"
            fab:fab_colorNormal="@color/orange"
            fab:fab_colorPressed="@color/orange_pressed"
            fab:fab_title="Menu 2" />


    </com.getbase.floatingactionbutton.FloatingActionsMenu>

</FrameLayout>

在此先感谢,
帕万

4

2 回答 2

1

我不知道您的代码,但我假设您使用的是 ActionbarActivity。那里使用的 Actionbar 不属于你的布局,因此 FrameLayout 不会在它上面绘制。

按照这篇文章创建一个布局,您可以在其中控制 ActionBar(使用工具栏):http: //javatechig.com/android/android-lollipop-toolbar-example

如果这不是问题,您可以尝试在布局上调用 View.bringToFront()。

于 2015-04-05T12:53:10.513 回答
1

您需要在布局中有工具栏并FrameLayout作为父级。然后,您可以在布局中拥有一个具有透明背景的视图,您可以在OnFloatingActionsMenuUpdateListener界面方法中显示和隐藏它。

于 2015-07-02T16:29:07.927 回答