Android Snackbar
2019-01-14 本文已影响3人
孤独的根号十二
public void showSnackbar(View v){
//LENGTH_INDEFINITE:无穷
Snackbar snackbar = Snackbar.make(v, "是否开启加速模式?", Snackbar.LENGTH_INDEFINITE);
snackbar.setAction("确定", new OnClickListener() {
@Override
public void onClick(View v) {
showCustomToast(null);
}
});
//不能设置多个action,会被覆盖
snackbar.setAction("取消", new OnClickListener() {
@Override
public void onClick(View v) {
showCustomToast(null);
}
});
snackbar.setCallback(new Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
// TODO Auto-generated method stub
showCustomToast(null);
super.onDismissed(snackbar, event);
}
@Override
public void onShown(Snackbar snackbar) {
// TODO Auto-generated method stub
super.onShown(snackbar);
}
});
snackbar.setActionTextColor(Color.RED);
snackbar.show();
}