@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab_add = (FloatingActionButton) findViewById(R.id.fab_add); FloatingActionButton fab_checkmark = (FloatingActionButton) findViewById(R.id.fab_checkmark); fab_add.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Open \"Add new item\" screen", Snackbar.LENGTH_SHORT) .setAction("Action", null) .show(); } }); fab_checkmark.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make( view, "Mark all selected items as done and hide them", Snackbar.LENGTH_SHORT) .setAction("Action", null) .show(); } }); fab_checkmark.hide(); }
private void attachFragment(String fragment, boolean isNew) { Fragment fragmentToAttach = null; boolean fabVisible = false; switch (fragment) { case Constants.FRAGMENT_LIST: textToFind = ""; fragmentToAttach = NoteListFragment.newInstance(folderId); if (folderId != trashNavId) // Folder list fabVisible = true; if (folderId != trashNavId && folderId != myNotesNavId) setOnTitleClickListener(true); else setOnTitleClickListener(false); break; case Constants.FRAGMENT_NOTE: Log.e(TAG, "NOTE FRAGMENT"); setOnTitleClickListener(true); fragmentToAttach = NoteFragment.newInstance(isNew, noteId, folderId); break; case Constants.FRAGMENT_TRASH_NOTE: setOnTitleClickListener(false); fragmentToAttach = TrashNoteFragment.newInstance(noteId); break; case Constants.FRAGMENT_SEARCH: setOnTitleClickListener(false); fragmentToAttach = SearchFragment.newInstance(textToFind); getSupportActionBar().setTitle(R.string.search); break; } fragmentManager .beginTransaction() .replace(R.id.container, fragmentToAttach, fragment) .commitAllowingStateLoss(); if (fabVisible) fab.show(); else fab.hide(); }
/** To hide fab, you need to remove its anchor */ private void hideFab() { // Ugly bug makes the view go to bottom|center of screen before hiding, seems like you need to // implement your own fab behavior... fabPhoto.setVisibility(View.GONE); final CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) fabPhoto.getLayoutParams(); layoutParams.setAnchorId(View.NO_ID); fabPhoto.requestLayout(); fabPhoto.hide(); }
private void setupFab(View v) { addItemFab = (FloatingActionButton) v.findViewById(R.id.addItemInventoryFab); if (PrimaryUser.getInstance().equals(user)) { addItemFab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { addItemButtonClicked(); } }); } else { addItemFab.hide(); } }
private boolean updateFab(FloatingActionButton child, View dependency) { float toolbarPosition = dependency.getY(); // toolbar is gone if (toolbarPosition + mActionBarSize == 0) { child.hide(); } // toolbar is visible else { child.show(); } return toolbarPosition != 0; }
@Override public void onNestedScroll( CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { super.onNestedScroll( coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) { child.hide(); } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) { child.show(); } }
private void startRipple() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout); Drawable d = coordinatorLayout.getBackground(); final RippleDrawable rippleDrawable = (RippleDrawable) d; rippleDrawable.setHotspot( mReset.getX() + mReset.getWidth() / 2, mReset.getY() + mReset.getHeight() / 2); rippleDrawable.setState( new int[] {android.R.attr.state_pressed, android.R.attr.state_enabled}); coordinatorLayout.getBackground().setState(new int[] {}); } mReset.hide(); mElapsedTime = 0; setTime(); }
@Override public void onNestedScroll( final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, final View target, final int dxConsumed, final int dyConsumed, final int dxUnconsumed, final int dyUnconsumed) { super.onNestedScroll( coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) { // User scrolled down and the FAB is currently visible -> hide the FAB child.hide(); } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) { // User scrolled up and the FAB is currently not visible -> show the FAB child.show(); } }
@Override public void onHandleStateChanged(FastScrollerHandleState newState) { if (newState == FastScrollerHandleState.PRESSED) fabOpenRecent.hide(); }
@Override public void hideFab() { floatingActionButton.hide(); fabIsHidden = true; }