【发布时间】:2018-12-07 16:13:28
【问题描述】:
【问题讨论】:
标签: android material-design android-snackbar material-components-android googleio
【问题讨论】:
标签: android material-design android-snackbar material-components-android googleio
在Material Components library 中使用Snackbar。
默认情况下,它具有圆角。
使用setAnchorView 方法使Snackbar 出现在特定视图上方,在您的情况下为fab 按钮。
Snackbar snackbar = Snackbar.make(view, "...", Snackbar.LENGTH_LONG);
snackbar.setAnchorView(fab);
snackbar.show();
您还可以使用应用主题中的 snackbarStyle 属性自定义边距。
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
....
<item name="snackbarStyle">@style/MySnackbar</item>
</style>
在快餐栏样式中使用 android:layout_margin 属性。
<style name="MySnackbar" parent="@style/Widget.MaterialComponents.Snackbar">
<item name="android:layout_margin">32dp</item>
</style>
【讨论】:
Snackbar 仍然没有圆角。
这是 Google 最近推出的 Material Components 包的一部分。 可能在:-
com.google.android.material:material:1.0.0-alpha3
而它仍在 alpha 中。所以我不太确定你是否可以在生产中使用它。我在下面附上了一些链接。
【讨论】:
尝试添加此依赖项。
implementation 'com.github.danimahardhika:cafebar:1.3.1'
然后可以使用此代码添加咖啡吧。
CafeBar.builder(context)
.theme(CafeBarTheme.LIGHT)
.duration(CafeBar.Duration.MEDIUM)
.content(R.string.text)
.neutralText("Action")
//You can parse string color
.neutralColor(Color.parseColor("#EEFF41"))
//Or use color resource
.neutralColor(R.color.neutralText)
.show();
如果您需要更多自定义,请访问文档here。
【讨论】: