【发布时间】:2021-04-15 16:48:26
【问题描述】:
【问题讨论】:
标签: android material-design android-styles android-snackbar
【问题讨论】:
标签: android material-design android-styles android-snackbar
只有当 UI 不使用应用栏或底部导航栏等持久导航组件时,Snackbar 才能跨越整个屏幕宽度。 跨越整个 UI 宽度的 Snackbars 只能在 FAB 出现时向上推。
由于我没有您的代码,您可以尝试设置Snackbar 的样式,方法是在您的AppTheme 中的styles.xml 或themes.xml 中添加这一行:
<item name="snackbarStyle">@style/Widget.MaterialComponents.Snackbar.FullWidth</item>
或者以编程方式您可以试试这个:
// Create the Snackbar
Snackbar snackbar = Snackbar.make(containerLayout, "", Snackbar.LENGTH_LONG);
// Get the Snackbar's layout view
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();
//If the view is not covering the whole snackbar layout, add this line
layout.setPadding(0,0,0,0);
// Show the Snackbar
snackbar.show();
【讨论】: