0

When I am expanding floating action button it keep remain expanded until I click on that again to collapse.

My question is there any way to automatically collapse floating action button after some times from expanding state.

dan1st
  • 12,568
  • 8
  • 34
  • 67
0xAliHn
  • 18,390
  • 23
  • 91
  • 111

1 Answers1

0

Use a Handler with a delay:

public class HideFabActivity extends AppCompatActivity{
    private final int DELAY = 5000;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

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

         new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                fab.hide();
            }
        }, DELAY);
}

Check out this SO post re using Handler to make a Splash page.

Community
  • 1
  • 1
frogleaf
  • 43
  • 6