title: Disable the floating action button programmatically
body: <p>I have a floating action button, I want to deactivate or disable it for guest users (my guest users are when the <code>userId == null</code>).</p>
  <p>I tried to use <code>if...else</code>, but it did not work and the floating action button is still active for guest user.</p>
  <pre><code>import android.os.Bundle;
  
  import com.google.android.material.floatingactionbutton.FloatingActionButton;
  import com.google.android.material.snackbar.Snackbar;
  
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.appcompat.widget.Toolbar;
  
  import android.view.View;
  import android.widget.Toast;
  
  public class inset extends AppCompatActivity {
      private String USER_ID;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_inset);
          Toolbar toolbar = findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          FloatingActionButton fab = findViewById(R.id.fab);
  
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  Snackbar.make(view, &quot;Replace with your own action&quot;, Snackbar.LENGTH_LONG)
                              .setAction(&quot;Action&quot;, null).show();
  
              }
          });
      }
  
  }
  </code></pre>