Snackbar is not working within fragment class

You can also use:

getActivity().findViewById(android.R.id.content)

like this:

Snackbar snackBar = Snackbar.make(getActivity().findViewById(android.R.id.content),
           "Look at me, I'm a fancy snackbar", Snackbar.LENGTH_LONG);
snackBar.show();

See this


I have solved this:

It is fine if we do not include CoordinatedLayout to my fragment_home.xml

Solution:

Defined : private RelativeLayout mRoot;

Now initialize in initUI(View view)

mRoot = (RelativeLayout) view.findViewById(R.id.mainrl);

and on Button click event put the following code:

 Snackbar.make(mRoot, "Had a snack at Snackbar", Snackbar.LENGTH_LONG).show();

Now main thing about this is:

just change current theme to Theme.AppCompat.Light.NoActionBar

It Done.!!!