Snack bar not displayed

自作多情 提交于 2019-12-03 14:19:13
Mohammed Rampurawala

Make a public method in a Util class and dont make the cordinatorLayout as public static. Keep the weakReference of your Activity's instance and through that you can show the SnackBar. Method given below.

public void showSnackBar(Activity activity, String message){
    View rootView = activity.getWindow().getDecorView().findViewById(android.R.id.content);
    Snackbar.make(rootView, message, duration).show();
}
chintan
private static final String message = "No Internet Connection";

public  static void message(Activity activity) {
    View rootView = activity.getWindow().getDecorView().findViewById(android.R.id.content);
    Snackbar.make(rootView, message, Snackbar.LENGTH_LONG).show();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!