Colorful Snackbar

Hey,

This code segment helps you to customize snackbar. You can create amazing stylish snackbar.

/**
 * Created by freakycoder on 09/12/15.
 */

public class ColorfulSnackbar {

    private static final int red = Color.parseColor("#f41515");
    private static final int green = 0xff4caf50;
    private static final int blue = 0xff2195f3;
    private static final int orange = 0xffffc107;
    private static final int myBlue = Color.parseColor("#002487");

    private static View getSnackBarLayout(Snackbar snackbar) {
        if (snackbar != null) {
            return snackbar.getView();
        }
        return null;
    }

    private static Snackbar colorSnackBar(final Snackbar snackbar, int colorId) {
        View snackBarView = getSnackBarLayout(snackbar);
        if (snackBarView != null) {
            snackBarView.setBackgroundColor(myBlue);
            // Changing action button text color
            View sbView = snackbar.getView();
            TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
            textView.setTextColor(Color.WHITE);
        }
        return snackbar;
    }

    public static Snackbar info(Snackbar snackbar) {
        return colorSnackBar(snackbar, blue);
    }

    public static Snackbar warning(Snackbar snackbar) {
        return colorSnackBar(snackbar, orange);
    }

    public static Snackbar alert(Snackbar snackbar) {
        return colorSnackBar(snackbar, red);
    }

    public static Snackbar confirm(Snackbar snackbar) {
        return colorSnackBar(snackbar, green);
    }
}

USAGE :
//Default snackbar creation
Snackbar snackbar = Snackbar.make(findViewById(R.id.mainRelativeLayout), "Snackbar", Snackbar.LENGTH_LONG);//Your custom snackbar
ColorfulSnackbar.info(snackbar).show();
And that’s it. It is so simple and clear.
If you have any question, ask me :)

How to extract filename from Uri?

Now, we can extract filename with and without extension :) You will convert your bitmap to uri and get the real path of your file. Now w...