Blankj / AndroidUtilCode

:fire: Android developers should collect the following utils(updating).
https://blankj.com/2016/07/31/android-utils-code/
Apache License 2.0
33.36k stars 10.69k forks source link

Snackbar #106

Closed DanteAndroid closed 7 years ago

DanteAndroid commented 7 years ago

虽然snackbarUtils封装了很强大的snackbar,但是有时候只需要简单的功能啊。。不需要设置background啥的。。同样的ToastUtils可以传入简单的参数,而snackBar却没有。建议添加。 示例:

    public static void showSnack(View rootView, int textId) {
        if (null != rootView) {
            Snackbar.make(rootView, textId, Snackbar.LENGTH_SHORT).show();
        }
    }

    public static void showSnack(View rootView, String text) {
        if (null != rootView) {
            Snackbar.make(rootView, text, Snackbar.LENGTH_SHORT).show();
        }
    }

    public static void showSnackLong(View rootView, int textId) {
        if (null != rootView) {
            Snackbar.make(rootView, textId, Snackbar.LENGTH_LONG).show();
        }
    }
    public static void showSnackLong(View rootView, String text) {
        if (null != rootView) {
            Snackbar.make(rootView, text, Snackbar.LENGTH_LONG).show();
        }
    }

因为我不会pull request,所以只能这样啦。麻烦了。或者告诉我怎么用Pull呢~

Blankj commented 7 years ago

:+1:

KosmoSakura commented 7 years ago

public static void kosmosSnackbar(View parent, CharSequence text) { showShortSnackbar(parent, text, Color.parseColor("#ffffff"), Color.parseColor("#333333")); }

public static void kosmosSnackbar(View parent, CharSequence text, CharSequence action, View.OnClickListener listener) {
    kosmosSnackbar(parent, text, Snackbar.LENGTH_SHORT, Color.parseColor("#ffffff"), Color.parseColor("#333333"), action, Color.parseColor("#01b5c6"), listener);
}

我在你的基础上做了个简单的封装,

zuoer8676 commented 7 years ago

kosmosSnackbar方法参数太多,调用传入的时候容易弄错

KosmoSakura commented 7 years ago

kosmosSnackbar(View parent, CharSequence parent) parent 是依附的控件,parent是显示的文字 * 下面重载的方法是增加了右边按钮的点击监听