Dmitry Smolyaninov Dmitry Smolyaninov - 1 year ago 120
Android Question

Hide/Show floating action button during FragmentTransection

I have this code for open some Message Fragment.

private void openMessage(int position) {
MessageRecord item = data.get(position);
List<MessageRecord> tmp = new ArrayList<>(data);

MessagesActivity2 parentActivity = ((MessagesActivity2) context);
FragmentTransaction ft = parentActivity.getSupportFragmentManager().beginTransaction();

MessageFragment fragment1 = MessageFragment.newInstance(item);
ft.add(, fragment1);



And this line hides my fab.

But I cant figure out how to reopen my FAB after i press Back button and return to the view of the activity.
Thanks in advance for help, guys!

Isj Isj
Answer Source

Override onBackPressed() in the activity and inside check if the fragment is null or not as per your requirement, then hide your FAB.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download