Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Snackbar width is not setting MATCH_PARENT in Tablets

Tags:

android

Snackbar width is matching to full width in mobiles but its not setting match_parent when running in tablet. Kindly help me!Code is below

final Snackbar mSnackbar = Snackbar.make(view, "", Snackbar.LENGTH_LONG);
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) mSnackbar.getView();
layout.setPadding(0,0,0,0);
TextView textView = (TextView) 
layout.findViewById(android.support.design.R.id.snackbar_text);
textView.setVisibility(View.INVISIBLE);
snackView = inflater.inflate(R.layout.snackbar_layout, null);
layout.addView(snackView, 0);
like image 625
Darsy Avatar asked Dec 11 '22 10:12

Darsy


2 Answers

Use the following code snippet to support full width in tablet landscape mode:

Snackbar snackbar = Snackbar.make(view, "Sample Text", Snackbar.LENGTH_LONG)
        .setAction("Sample Text", new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
(snackbar.getView()).getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
snackbar.show();
like image 197
John Ruban Singh Avatar answered Apr 05 '23 23:04

John Ruban Singh


I think this is the default behavior of snackbar on tablets.for more information look here

like image 30
AskNilesh Avatar answered Apr 05 '23 23:04

AskNilesh