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

时间:2018-02-05 04:58:34

标签: android android-layout onclicklistener onblur android-framelayout

我希望我的背景模糊,其中有framelayout(用片段替换它)和bottom-navigation-view来选择片段。我也有fab菜单,onClick必须模糊背景中的一切,除了它自己 我已经坚持了这个问题差不多一个星期了。我已经尝试过堆栈溢出的所有答案。

这是我的底部导航代码,用于选择片段。我在这里使用了工厂。

 /**
 * 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);
}

}

这是活动的布局文件。 BTW,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中的内容变得模糊。 再一次,我已经尝试过stackoverflow中的所有内容,而且似乎对我有用。

1 个答案:

答案 0 :(得分:1)

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

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

                }
            });

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