-1

Can't click the button on SnackBar inside fragment with data binding.

Here's java code:

        final Snackbar snackBar = Snackbar.make(binding.layoutMain, error, Snackbar.LENGTH_LONG);

    snackBar.setAction("TRY", new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
    snackBar.show();

enter image description here

Edit: Connection Error is not a dialog.

UPDATE:

I tried setting the NestedScrollView's visibility to GONE just to test. Snackbar seems to work properly. Is it something to do with the layout?

JhesterMag
  • 71
  • 1
  • 9

3 Answers3

0

Do this way to achieve action on snackbar

     final Snackbar snackBar = Snackbar.make(binding.layoutMain, error, Snackbar.LENGTH_LONG).setAction("Dismiss", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
    //Do your code
  snackBar.dismiss();
            }
        });
        snackBar.show();
Milan Pansuriya
  • 2,521
  • 1
  • 19
  • 33
0

I did like this

  Snackbar snackbar = Snackbar.make( coordinator_,
            service_name+" Service Added To Cart!", 1000);

    //setting the snackbar action button text size
    View view = snackbar.getView();
    TextView txt_action = (TextView) view.findViewById(android.support.design.R.id.snackbar_action);
    TextView txt_text = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
    txt_action.setTextSize(13);
    txt_action.setAllCaps(false);
    txt_text.setTextSize(13);
    snackbar.setActionTextColor(ContextCompat.getColor(getActivity(), R.color.snackbar));

    snackbar.setAction("View Cart", new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //your code
        }
    });
    snackbar.show();
0

Try this.

Snackbar snackbar = Snackbar
        .make(cb,"Your Text",Snackbar.LENGTH_INDEFINITE)
        .setAction("COPY TO", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
Toast.makeText(getActivity(), "Clicked", Toast.LENGTH_SHORT).show();
            }
        });

snackbar.show();

and also try to dismiss Dialog of no connection on click of snack bar

flashberry
  • 153
  • 11