If one has implemented the Floating Action Button (FAB) in his android application and also there exists a Snackbar implementation in the same application, then the Snackbar is definitely going to overlap the Floating Action Button.
Make sure that add the dependency to the app-level Gradle file. After adding the dependency you need to click on the “Sync Now” button which appears at the top right corner of the Android Studio IDE.
When the user clicks on the Sync Now button make sure that you are connected to the network so that it can download the required files.
Refer to the below image if you can’t get the steps mentioned above:
Step 3: Add the FAB icons to the Drawable file
For demonstration purposes will import 3 icons in the Drawable folder, one can import the icons of his/her choice. One can do that by right-clicking drawable folder -> New -> Vector Asset. Refer to the following image to import the vector Icon.
Now select your vector icon:
Step 4: Working with the activity_main.xml file
In the activity_main.xml file add a Floating Action Button (FAB) and a Button. So whenever the user clicks on the Button then a Snackbar will pop up.
Invoke the following code inside the activity_main.xml file. For clear understanding refer the comments inside the code given below:
Now resolve the issue programmatically in MainActivity.java file.
One can observe below code that SHOW SNACKBAR button onclick listener we have set the AnchorView to the parent FAB. So that the parent FAB will be visible, even after the Snackbar pops up, and the Snackbar will be shown at the top of the FAB.
Invoke the following code and comments are added inside the code to understand the code in more detail.
Please Login to comment...