Android Custom Snackbar: can't remove margins

前端 未结 4 1063
北海茫月
北海茫月 2021-01-20 12:45

Regardless of whether or not it is a good idea to create a custom Snackbar, I have a custom Snackbar and I can\'t seem to get rid of the margins. I\'ve tried several things

相关标签:
4条回答
  • 2021-01-20 13:23

    In dimens.xml.

    Use this:

     <dimen name="design_snackbar_padding_horizontal">0dp</dimen>
    

    But remember that this will get applied to all the snackbars in your application.

    0 讨论(0)
  • 2021-01-20 13:29

    Add to theme of App or Activity <item name="snackbarStyle">@style/Widget.Design.Snackbar</item>

    0 讨论(0)
  • 2021-01-20 13:33

    Before showing the Snackbar you can remove the parent layout padding in the following way:

    //...
    _firmwareSnackbar.getView().setPadding(0,0,0,0);
    _firmwareSnackbar.show();
    
    0 讨论(0)
  • 2021-01-20 13:40

    You shoud remove paddings from a parent view:

    View snackBarLayout = findViewById(R.id.mainLayout);
    Snackbar globalSnackbar = Snackbar.make(snackBarLayout, "", Snackbar.LENGTH_INDEFINITE);
    Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) globalSnackbar.getView();  
    
    layout.setPadding(0,0,0,0); 
    
    0 讨论(0)
提交回复
热议问题