Java Code Examples for android.support.design.widget.Snackbar#addCallback()
The following examples show how to use
android.support.design.widget.Snackbar#addCallback() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonUtils.java From Awesome-WanAndroid with Apache License 2.0 | 6 votes |
/** * Show message * * @param activity Activity * @param msg message */ public static void showSnackMessage(Activity activity, String msg) { LogHelper.e("showSnackMessage :" + msg); //去掉虚拟按键 activity.getWindow().getDecorView().setSystemUiVisibility( //隐藏虚拟按键栏 | 防止点击屏幕时,隐藏虚拟按键栏又弹了出来 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE ); final Snackbar snackbar = Snackbar.make(activity.getWindow().getDecorView(), msg, Snackbar.LENGTH_SHORT); View view = snackbar.getView(); ((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(ContextCompat.getColor(activity, R.color.white)); snackbar.setAction("知道了", v -> { snackbar.dismiss(); //隐藏SnackBar时记得恢复隐藏虚拟按键栏,不然屏幕底部会多出一块空白布局出来,很难看 activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); }).show(); snackbar.addCallback(new BaseTransientBottomBar.BaseCallback<Snackbar>() { @Override public void onDismissed(Snackbar transientBottomBar, int event) { super.onDismissed(transientBottomBar, event); activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } }); }
Example 2
Source File: MainActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 6 votes |
private void listing13_27() { View coordinatorLayout = findViewById(R.id.coordinatorlayout); // Listing 13-27: Building and showing a Snackbar Snackbar snackbar = Snackbar.make(coordinatorLayout, "Deleted", Snackbar.LENGTH_LONG); // Define the action snackbar.setAction("Undo", new View.OnClickListener() { @Override public void onClick(View view) { // TODO Undo the deletion } }); // React to the Snackbar being dismissed snackbar.addCallback(new Snackbar.Callback() { @Override public void onDismissed(Snackbar transientBottomBar, int event) { // TODO Finalize the deletion } }); // Show the Snackbar snackbar.show(); }
Example 3
Source File: Alert.java From outlay with Apache License 2.0 | 5 votes |
public static void info(View view, String message, View.OnClickListener clickListener, Snackbar.Callback callback) { Context context = view.getContext(); Snackbar bar = Snackbar.make(view, message, Snackbar.LENGTH_LONG); if (clickListener != null) { bar.setAction(context.getString(app.outlay.R.string.label_undo), clickListener); bar.setActionTextColor(ContextCompat.getColor(context, app.outlay.R.color.red)); } if(callback != null) { bar.addCallback(callback); } bar.show(); }