Snack bar not displayed

后端 未结 1 2028
Happy的楠姐
Happy的楠姐 2021-02-15 08:33

I\'m inheriting from BaseActivity for all the other activities.

public class BaseActivity extends AppCompatActivity {

    public static Coordinator         


        
1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-15 08:56

    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();
    }
    

    0 讨论(0)
提交回复
热议问题