当前位置:网站首页>Snackbar使用详解
Snackbar使用详解
2022-06-10 12:55:00 【yechaoa】
Snackbar是介于Toast与Dialog之间的一个控件,既可以像Toast一样自动消失,也可以像Dialog一样交互消失。
使用与Toast相似:
Snackbar.make(view, "已加入行程", Snackbar.LENGTH_SHORT).show();第一个参数是view,任意都行,但是google官方建议传入CoordinatorLayout,一来在Snackbar显示的时候可以右滑移除,二来在Snackbar显示的时候布局会自动变
第二个参数是message,即提示的内容
第三个参数是显示的时长,Snackbar.LENGTH_SHORT 短时间显示且自动消失,Snackbar.LENGTH_LONG 长时间显示且自动消失,Snackbar.LENGTH_INDEFINITE 不消失显示 用在加了Action的情况下,在用户点击之后再消失。
高级一点的使用(改颜色,加Action,加回调):
final Snackbar mSnackbar = Snackbar.make(view, "已加入行程", Snackbar.LENGTH_INDEFINITE);
//设置Snackbar的背景颜色
mSnackbar.getView().setBackgroundColor(ContextCompat.getColor(MainActivity.this,R.color.colorPrimary));
//设置Action文字的背景颜色
mSnackbar.setActionTextColor(Color.WHITE);
//设置Action并监听事件
mSnackbar.setAction("知道了", new View.OnClickListener() {
@Override
public void onClick(View view) {
//to do something
}
})
.show();
//添加回调
mSnackbar.addCallback(new Snackbar.Callback(){
@Override
public void onDismissed(Snackbar transientBottomBar, int event) {
super.onDismissed(transientBottomBar, event);
Log.i(TAG, "onDismissed(MainActivity.java:62)--->> " + "onDismissed");
}
@Override
public void onShown(Snackbar sb) {
super.onShown(sb);
Log.i(TAG, "onShown(MainActivity.java:68)--->> " + "onShown");
}
});Material Design设计规范:按钮最多一个,且提示文字是短文本
边栏推荐
- Mysql database (26): View
- 什么是基因的p值?
- Apple邮箱配置QQ邮箱,163邮箱,edu邮箱,gmail邮箱,获取gmail日历
- 2022 ciscn preliminary PWN complete WP
- Dynaslam ii: carefully coupled multi object tracking and slam
- Commencez par interpréter le Code généré automatiquement par la BDC et expliquez les composantes du programme de l'interface graphique SAP.
- Ekuiper newsletter 2022-05 protobuf codec support, visual drag and drop writing rules
- [mobile robot] principle of wheel odometer
- In June, 2022, China Database ranking: tidb made a comeback to win the crown, and Dameng was dormant and won the flowers in May
- 12、 Process address space (PMAP; vdso; MMAP)
猜你喜欢
![buuctf [Discuz]wooyun-2010-080723](/img/b9/d63c9c638ff7c390c490d6fd5eafd1.png)
buuctf [Discuz]wooyun-2010-080723

谷歌提出超强预训练模型CoCa,在ImageNet上微调Top-1准确率达91%!在多个下游任务上SOTA!

Leetcode 96. 不同的二叉搜索樹

CL210OpenStack操作的故障排除--常见核心问题的故障排除

Recommended learning materials for Altium Designer

【NLP】NLP全路径学习推荐

什么是基因的p值?
![[flinlk] dynamic Kerberos authentication in Flink pit](/img/ba/3a85df364ae0bcfca38e5f26366c03.png)
[flinlk] dynamic Kerberos authentication in Flink pit

Commencez par interpréter le Code généré automatiquement par la BDC et expliquez les composantes du programme de l'interface graphique SAP.

Sohu employees encounter wage subsidy fraud. What is the difference between black property and gray property and how to trace the source?
随机推荐
'setbackgrounddrawable() 'is deprecated, setbackgrounddrawable is obsolete
施一公等团队登Science封面:AI与冷冻电镜揭示「原子级」NPC结构,生命科学突破
常识,神经元数量,小鼠的脑内神经元大约在7000万个、人类约有860亿个
change system time
谷歌提出超强预训练模型CoCa,在ImageNet上微调Top-1准确率达91%!在多个下游任务上SOTA!
【FAQ】运动健康服务REST API接口使用过程中常见问题和解决方法总结
[NLP] NLP full path learning recommendation
Unity typewriter to automatically roll text to the bottom of the text box
Error:top-left corner pixel must be either opaque white or transparent.
Which EDA design software should Altium Allegro pads choose
移动app性能测试有哪些需要进行?性能测试报告如何收费?
On distributed transaction
Recommend an efficient IO component - okio
Simple integration of client go gin six list watch two (about the improvement of RS, pod and deployment)
WT2003H4-16S 语音芯片按键录音及播放应用解析
10、 Application of state machine model (cellular automata; gdb/rr/perf; code verification tool)
Handling work ticket system
How about the one-stop machine learning opening platform mlflow?
QT database application 22 file coding format recognition
The deep neural network classifies nearly 2billion images per second, and the new brain like optical classifier chip is on nature