1

I've declared a FloatingActionButton and I want it to appear only when the app is accessed by admin, so I need to make it visible(as I made it by default invisible).

I tried using .setVisibility, but it says .setVisibility can only be called from within the same library.

<com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/add_event_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="16dp"
    android:layout_marginBottom="16dp"
    android:clickable="true"
    android:focusable="true"
    android:visibility="invisible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:srcCompat="@mipmap/add_icon1"
    />
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841

2 Answers2

0

You can check the official doc:

Use the show and hide methods to animate the visibility of a FloatingActionButton. The show animation grows the widget and fades it in, while the hide animation shrinks the widget and fades it out.

Just use:

FloatingActionButton fab1 = findViewById(R.id.add_event_btn);
fab1.show();

Also, in the version 1.1.0 the method setVisibility is not restricted.

You can use:

fab1.setVisibility(View.VISIBLE);
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
-2

Try getting a reference to your floating action button in your code, lets say its mFab, and do this:

mFab.setVisibility = View.INVISIBLE

or

mFab.setVisibility = View.GONE

Jason
  • 284
  • 2
  • 10