单击 fab 菜单时使用片段(Framelayout)模糊背景

Blur background with fragment(Framelayout) when fab menu is clicked

我想让我的背景变得模糊,它有框架布局(用于用片段替换它)和底部导航视图 select 片段。我还有很棒的菜单,onClick 必须模糊背景中的所有内容,除了它本身。
我在这个问题上被困了将近一个星期。我已经尝试了堆栈溢出及以后的所有答案。

这是我的底部导航代码,用于select片段。我用过这里的晶圆厂

 /**
 * Created by VISHNU and AUGUSTINE at Thursday  on 21-12-2017.
 */

public class Bottomnav extends AppCompatActivity {

//Custom Bottom navigation library...
private BottomNavigationViewEx bottomNavigation;

private Fragment fragment;
private FragmentManager fragmentManager;
FrameLayout frm_blur;

FloatingActionMenu menu;
ImageView img;

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



    FloatingActionButton fab = findViewById(R.id.fab);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Reg_contacts frag1 = new Reg_contacts();
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

            transaction.replace(R.id.main_container, frag1);

            transaction.commit();

            Bungee.zoom(Bottomnav.this);
        }

    });

    FloatingActionButton fab_search = findViewById(R.id.search_fab);
    fab_search.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Search frag1 = new Search();
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

            transaction.replace(R.id.main_container, frag1);

            transaction.commit();

            Bungee.zoom(Bottomnav.this);
        }

    });



    //Setting bottom nav properties...
    bottomNavigation = (BottomNavigationViewEx) findViewById(R.id.bottom_navigation);
    bottomNavigation.enableShiftingMode(false);
    bottomNavigation.enableItemShiftingMode(false);
    bottomNavigation.setSelectedItemId(R.id.search);




    fragmentManager = getSupportFragmentManager();
    bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {


        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            String title;
            int id = item.getItemId();
            switch (id){

                case R.id.search:

                    fragment = new Search();

                    break;
                case R.id.todo:
                    fragment = new ServiceTable();

                    break;
                case R.id.info:
                    fragment = new Orderlist();
                    //getSupportActionBar().setTitle("Order List");
                    break;
                case R.id.close:
                    toExit();
                    break;
            }

            final FragmentTransaction transaction = fragmentManager.beginTransaction();
            transaction.replace(R.id.main_container, fragment).commit();


            return true;
        }
          // change to whichever id should be default
       // }
    });

    if (savedInstanceState == null) {
        bottomNavigation.setSelectedItemId(R.id.search);
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.bottom_menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    return super.onOptionsItemSelected(item);
}
boolean doubleBackToExitPressedOnce = false;

public void toExit(){

    if (doubleBackToExitPressedOnce) {
        finishAffinity();
    }
    this.doubleBackToExitPressedOnce = true;
    Toast.makeText(this, "Press again to exit", Toast.LENGTH_SHORT).show();


    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            doubleBackToExitPressedOnce = false;
        }
    }, 1500);
}


public void setActionBarTitle(String title) {
    getSupportActionBar().setTitle(title);
}

}

这是 activity 的布局文件。顺便说一句,BottomNavigationView 和 Fab 是自定义库。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.vishnu.vijaytrial.Bottomnav">

<FrameLayout
    android:id="@+id/main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottom_navigation"
    android:layout_alignParentTop="true">

</FrameLayout>


<FrameLayout
    android:id="@+id/main_container1"
    android:layout_marginStart="220dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/bottom_navigation"
    >


    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/fab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_gravity="bottom|end"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        fab:menu_colorNormal="#83c236"
        fab:menu_colorPressed="#6c9f2e"
        fab:menu_colorRipple="#99FFFFFF"
        fab:menu_fab_hide_animation="@anim/fab_slide_in_from_left"
        fab:menu_fab_show_animation="@anim/fab_slide_out_to_left"
        fab:menu_fab_size="normal"
        fab:menu_icon="@drawable/fab_add"
        fab:menu_labels_colorNormal="@android:color/holo_purple"
        fab:menu_labels_colorPressed="#444444"
        fab:menu_labels_colorRipple="#66FFFFFF"
        fab:menu_labels_cornerRadius="3dp"
        fab:menu_labels_hideAnimation="@anim/fab_slide_out_to_right"
        fab:menu_labels_position="left"
        fab:menu_labels_showAnimation="@anim/fab_slide_in_from_right"
        fab:menu_labels_textColor="#FFFFFF"

        fab:menu_labels_textSize="14sp"
        fab:menu_openDirection="up">


        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_marginBottom="8dp"
            android:layout_marginRight="8dp"
            android:src="@drawable/fab_add"
            fab:fab_colorNormal="#4aa6ec"
            fab:fab_colorPressed="#3a8bc9"
            app:fab_size="mini"
            fab:fab_colorRipple="#b9aeaeae"
            fab:fab_label="Register"
            />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/search_fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_size="mini"
            android:layout_gravity="bottom|right"
            android:layout_marginBottom="8dp"
            android:layout_marginRight="8dp"
            android:src="@drawable/ic_search_black_24dp"
            fab:fab_colorNormal="#4aa6ec"
            fab:fab_colorPressed="#3a8bc9"
            fab:fab_colorRipple="#b9aeaeae"
            fab:fab_label="Search"
            />


    </com.github.clans.fab.FloatingActionMenu>

</FrameLayout>




<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:itemBackground="@color/colorPrimary"
    app:itemIconTint="@drawable/color"
    app:itemTextColor="@drawable/color"
    android:layout_alignParentBottom="true"
    app:menu="@menu/bottom_menu">

</com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx>

</RelativeLayout>

当点击 FAb 菜单时,我希望 framelayout 中的内容变得模糊。 再一次,我已经尝试了 Whosebug 中的所有内容,但似乎没有什么对我有用。

 floatingActionMenu.setOnFloatingActionsMenuUpdateListener(new 
 FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() {
                @Override
                public void onMenuExpanded() {
                     yourView.getBackground().setAlpha(100);
                }

                @Override
                public void onMenuCollapsed() {
                     yourView.getBackground().setAlpha(255);

                }
            });

您应该相应地替换视图 floatingActionMenu 和 yourView(FrameLayout)。