How to show snackbar throughout the Application?

31
January 12, 2019, at 8:00 PM

I have more than 3 Activity but let's just take three of them, BaseActivity, Splashscreen, MainActivity. Splashscreen and Mainactivity extends BaseActivity. Now i am showing a Snackbar inside the BaseActivity whenever I get failureresponse from the server. The response code is in BaseActivity and parallely i am transitioning from splashscreen to MainActivity.

The snackbar is not showing up? What could be the error? is there a way to make static snackbar? i have tried it but didnt get the getWindow from a static method? Anyone faced this problem?

Answer 1

Yes you can create a static method in your utils and create snack bar in utils class and use anywhere in your app

     public static void showSnackBar(View view, String msg) {
        if (view != null) {
            Snackbar snackbar = Snackbar.make(view, msg, Snackbar.LENGTH_LONG);
            View snackbarView = snackbar.getView();
            TextView textView = snackbarView.findViewById(android.support.design.R.id.snackbar_text);
            textView.setMaxLines(5);
//snackBarView.setBackgroundColor(Color.argb(255, 8, 20, 37));
            snackbar.show();
        }
    }

Use:

Utils.showSnackBar(getView(), failureMessage);
READ ALSO
Androidx Preferences not incuding RingtonePreference

Androidx Preferences not incuding RingtonePreference

I'm doing the settings activity for my app via code since the xml editor wont find any preferences but PreferenceScreenVia code everything is working but I can not find the RingtonePreferences from Androidx, the only one I find is the one from android

66
How to access dynamic layout in adapter?

How to access dynamic layout in adapter?

I have one adapter in which I have one button, I will click on that button and opening alert dialogue with Yes and No buttonsNow if user will click on that button I am creating one dynamic layout with linear layout and converting it to Image and share it with Installed...

41
i want to make a seekbar with this different background drawbles

i want to make a seekbar with this different background drawbles

see image over here I have already completed adding flags but with different backgrounds seems quite difficult I want to make an seekbar like this any suggestion thanks in advance

45