[Snackbar] Can't change top and bottom padding of snackbar's text view
See original GitHub issueDescription:
Setting <item name="android:padding">0dp</item>
changes the start and end padding but the top and bottom remain unchanged.
Setting android:paddingTop
and android:paddingBottom
has the same effect.
From the layout inspector
Expected behavior: The top and bottom padding change, similar to start and end.
Source code:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="snackbarTextViewStyle">@style/AppTheme.Snackbar.TextView</item>
</style>
<style name="AppTheme.Snackbar.TextView" parent="@style/Widget.MaterialComponents.Snackbar.TextView">
<item name="android:padding">0dp</item>
</style>
Android API version: 29
Material Library version: 1.2.0-alpha05
Device: Android Emulator - Pixel 2
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Add margins to Snackbar view - android - Stack Overflow
By adding padding or margins to your CoordinatorLayout you can control the position and move the Snackbar from the bottom of the screen....
Read more >Snackbars - Material Design
Anchoring a snackbar By default, Snackbars will be anchored to the bottom edge of their parent view. However, you can use the setAnchorView...
Read more >How To Create a Snackbar / Toast - W3Schools
Snackbar / Toast. Snackbars are often used as tooltips/popups to show a message at the bottom of the screen. Click on the button...
Read more >Android Snackbar Example Tutorial - DigitalOcean
A code snippet to display a basic android Snackbar is shown below. ... No changes in the activity_main.xml code which contains the ...
Read more >Configuring Snackbar in Jetpack Compose when using ...
I would like to show you one approach you could take in setting up snackbars for your Android application using Scaffold. This is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just went through the source and found a way of updating the padding of the Snackbar. I’ll explain the steps that I went through, see tl;dr at the end.
Snackbar.java
In Snackbar.java on line167 you can see it inflating one of two layouts:
R.layout.mtrl_layout_snackbar_include : R.layout.design_layout_snackbar_include
In those layouts you see almost two similar layouts, just different stylings and references. What they have in common though is the TextView and Button. The TextView is named: android:id=“@+id/snackbar_text”
However this snackbar_text isn’t used anywhere in snackbar.java but after some more investigation I found it’s used in
SnackbarContentLayout
referenced all over the place, but most importantly on line 163 in snackbar.java.SnackbarContentLayout
Going into this SnackbarContentLayout I looked for
snackbar_text
which is assigned tomessageView
. Following this messageView you quickly find line124 where it’s doing a condition if the textview contains a single or multilines updating the bottom and top padding.Following back where
updateViewsWithinLayout
is called from (line101) you see it’s choosing between a multiLineVPadding or singleLineVPadding.Following
multiLineVPadding
you’ll see it assigned on line91Finally looking up
design_snackbar_padding_vertical_2lines
you’ll see it has 24dp assigned.Tl;dr
The padding of the Snackbar varies between singleline (14dp) and multiline (24dp). You need to somehow override this. This can be done by overriding this value in your
dimens.xml
for example.You can set your theme’s
snackbarStyle
withandroid:paddingTop
andandroid:paddingBottom
to achieve increase the padding.Are you trying to remove all top and bottom padding?