It is necessary to darken and block all elements on the screen by pressing the floatingActionButton , while adding two new buttons. initial state

Final state

How can I do that?

  • As an option, you can add on top a darkened layer that has your buttons. - Nikotin N
  • Via setContentView can I upload any other xml markup? If this is not the case, I just need to darken the current content, and on top of it there are 2 buttons. - Frozik6k
  • Try this library. I hope it helps you ... - DevOma

1 answer 1

In the end, he figured it out himself. In the main layout placed two buttons in the container FrameLayout

 <?xml version="1.0" encoding="utf-8"?> 

 <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:openDrawer="start"> <include layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height="match_parent"/> <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer"/> </android.support.v4.widget.DrawerLayout> <FrameLayout android:id="@+id/linGroupButtonAdd" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" android:background="@color/colorBackgroud"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right" android:orientation="vertical"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/box"/> <android.support.design.widget.FloatingActionButton android:id="@+id/fabAddBox" android:layout_width="wrap_content" android:layout_height="wrap_content" app:backgroundTint="@color/colorPrimaryDark" android:layout_margin="@dimen/fab_margin" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="@string/thing"/> <android.support.design.widget.FloatingActionButton android:id="@+id/fabAddThing" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="@dimen/fab_margin" /> </LinearLayout> </LinearLayout> </FrameLayout> 

here is the code for the main button FloatingActionButton

  FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ViewGroup linGroupButtonAdd = (ViewGroup) findViewById(R.id.linGroupButtonAdd); linGroupButtonAdd.setVisibility(View.VISIBLE); Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.scale_fab); View viewAddThing = (View) findViewById(R.id.fabAddThing); viewAddThing.startAnimation(anim); viewAddThing.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(getApplicationContext(), "Добавить вещь", Toast.LENGTH_LONG).show(); } }); View viewAddBox = (View) findViewById(R.id.fabAddBox); viewAddBox.startAnimation(anim); view.setVisibility(View.GONE); } }); 

Color to darken:

  <color name="colorBackgroud">#ccffffff</color> 
  • It is not entirely clear how the blackout actually occurs. - pavlofff
  • The main FloatingActionButton button is located in the app_bar_main markup. After its pressing, the button itself disappears, at the same time the FrameLayout container is made visible with two buttons of the FloatingActionButton . The backgroud attribute of this container is assigned a white color with the alpha channel #ccffffff , and since the container is on top of the drawer_layout , it simply darkens it. The result is a darkened drawer_layout and two buttons that are located on the FrameLayout . - Frozik6k