0

Good afternoon,

I am working with Snackbars and I try to put an aciton (like UNDO), but the text is not aligned to the right of the screen.

The result I need :

enter image description here

The result I have :

enter image description here

As you can see, the "UNDO" action is not aligned right, as I need.

Here is my Snackbar code :

Snackbar snackbar = Snackbar.make(mMainContent, "Message deleted", Snackbar.LENGTH_LONG)
                        .setAction("UNDO", new View.OnClickListener() {
                            @Override
                            //Todo: Click on "UNDO"
                            public void onClick(View view) {
                            }
                        });

                snackbar.setActionTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));

                View snackbarView = snackbar.getView();
                snackbarView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
                snackbar.show();

Can someone help me ?

Thank you !

D. Math
  • 329
  • 6
  • 17

1 Answers1

0

Create your own custom snackbar layout Custom snackbar

The core part is below

<!-- language: lang-java -->

// Create the Snackbar
Snackbar snackbar = Snackbar.make(containerLayout, "", Snackbar.LENGTH_LONG);
// Get the Snackbar's layout view
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();
// Hide the text
TextView textView = (TextView) layout.findViewById(android.support.design.R.id.snackbar_text);
textView.setVisibility(View.INVISIBLE);

// Inflate our custom view
View snackView = mInflater.inflate(R.layout.my_snackbar, null);
// Configure the view
ImageView imageView = (ImageView) snackView.findViewById(R.id.image);
imageView.setImageBitmap(image);
TextView textViewTop = (TextView) snackView.findViewById(R.id.text);
textViewTop.setText(text);
textViewTop.setTextColor(Color.WHITE);

// Add the view to the Snackbar's layout
layout.addView(snackView, 0);
// Show the Snackbar
snackbar.show();
Community
  • 1
  • 1
noobEinstien
  • 3,147
  • 4
  • 24
  • 42