superToast 吐司

来源:互联网 发布:网络歌手花姐的真名 编辑:程序博客网 时间:2024/04/27 16:57
SuperToast 
看名字就知道,这东西是用来产生吐司效果的框架。有3中类型的吐司效果,分别是SuperToast,SuperActivityToast,SuperCardToast.这些用法都差不多,只是显示的在Activity里的布局不一样,前面两个都是浮动在Activity上,第三个则是产生在Activity布局的上端,都可以直接在activity和fragment中直接使用。
(一).SuperToast(最基本的吐司toast效果)
UI效果:

使用:
SuperToast superToast = new SuperToast(v.getContext());            superToast.setText("onClick!");            superToast.setDuration(SuperToast.Duration.VERY_SHORT);            superToast.setBackground(SuperToast.Background.BLUE);            superToast.setTextColor(Color.WHITE);            superToast.show();
// 设置进入动画                superToast.setAnimations(SuperToast.Animations.FADE);                superToast.setAnimations(SuperToast.Animations.FLYIN);                superToast.setAnimations(SuperToast.Animations.POPUP);                superToast.setAnimations(SuperToast.Animations.SCALE);// 设置停留时间                superToast.setDuration(SuperToast.Duration.SHORT);                superToast.setDuration(SuperToast.Duration.MEDIUM);                superToast.setDuration(SuperToast.Duration.LONG);// 设置背景                superToast.setBackground(SuperToast.Background.BLACK);                superToast.setBackground(SuperToast.Background.GRAY);                superToast.setBackground(SuperToast.Background.GREEN);                superToast.setBackground(SuperToast.Background.BLUE);                superToast.setBackground(SuperToast.Background.RED);                superToast.setBackground(SuperToast.Background.PURPLE);                superToast.setBackground(SuperToast.Background.ORANGE);// 设置文字大小                superToast.setTextSize(SuperToast.TextSize.SMALL);                superToast.setTextSize(SuperToast.TextSize.MEDIUM);                superToast.setTextSize(SuperToast.TextSize.LARGE);                // 设置文字                superToast.setText();                // 设置图标                superToast.setIcon(R.drawable.icon_message, SuperToast.IconPosition.BOTTOM);

(二). SuperActivityToast

在activity里直接使用一下代码即可,
 1.
 superActivityToast = new SuperActivityToast(getActivity(),                        SuperToast.Type.STANDARD);

2.
superActivityToast = new SuperActivityToast(getActivity(),                        SuperToast.Type.BUTTON);

3.
superActivityToast = new SuperActivityToast(getActivity(),                        SuperToast.Type.PROGRESS);

4.
superActivityToast = new SuperActivityToast(getActivity(),                        SuperToast.Type.PROGRESS_HORIZONTAL);


丰富的属性设置,这里列举一些重要的:
                // 设置动画                superActivityToast.setAnimations(SuperToast.Animations.FADE); // 淡入                superActivityToast.setAnimations(SuperToast.Animations.FLYIN);// 飞入                superActivityToast.setAnimations(SuperToast.Animations.POPUP);// 弹出                superActivityToast.setAnimations(SuperToast.Animations.SCALE);// 渐进 // 设置停留时间                superActivityToast.setDuration(SuperToast.Duration.SHORT);                superActivityToast.setDuration(SuperToast.Duration.MEDIUM);                superActivityToast.setDuration(SuperToast.Duration.LONG);                // 设置背景                superActivityToast.setBackground(SuperToast.Background.BLACK);                superActivityToast.setBackground(SuperToast.Background.GRAY);                superActivityToast.setBackground(SuperToast.Background.GREEN);                superActivityToast.setBackground(SuperToast.Background.BLUE);                superActivityToast.setBackground(SuperToast.Background.RED);                superActivityToast.setBackground(SuperToast.Background.PURPLE);                superActivityToast.setBackground(SuperToast.Background.ORANGE);// 设置文字 superActivityToast.setText(text); // 设置文字大小                superActivityToast.setTextSize(SuperToast.TextSize.SMALL);                superActivityToast.setTextSize(SuperToast.TextSize.MEDIUM);                superActivityToast.setTextSize(SuperToast.TextSize.LARGE);// 设置图片                superActivityToast.setIcon(SuperToast.Icon.Dark.INFO, SuperToast.IconPosition.LEFT);// 设置监听tosat消失后的事件                superActivityToast.setOnDismissWrapper(onDismissWrapper);                // 设置toast点击实践                superActivityToast.setOnDismissWrapper(onDismissWrapper);                 private OnClickWrapper onClickWrapper = new OnClickWrapper("onclickwrapper_one", new SuperToast.OnClickListener() {        @Override        public void onClick(View v, Parcelable token) {            SuperToast superToast = new SuperToast(v.getContext());            superToast.setText("onClick!");            superToast.setDuration(SuperToast.Duration.VERY_SHORT);            superToast.setBackground(SuperToast.Background.BLUE);            superToast.setTextColor(Color.WHITE);            superToast.show();        }    });    private OnDismissWrapper onDismissWrapper = new OnDismissWrapper("ondismisswrapper_one", new SuperToast.OnDismissListener() {        @Override        public void onDismiss(View view) {            SuperToast superToast = new SuperToast(view.getContext());            superToast.setText("onDismiss!");            superToast.setDuration(SuperToast.Duration.VERY_SHORT);            superToast.setBackground(SuperToast.Background.RED);            superToast.setTextColor(Color.WHITE);            superToast.show();        }    });
最后调用
superActivityToast.show()即可。
(三).SuperToastCrad
superCardToast = new SuperCardToast(getActivity(), SuperToast.Type.STANDARD);                               superCardToast = new SuperCardToast(getActivity(), SuperToast.Type.BUTTON);                                superCardToast = new SuperCardToast(getActivity(), SuperToast.Type.PROGRESS);                superCardToast = new SuperCardToast(getActivity(), SuperToast.Type.PROGRESS_HORIZONTAL);




0 1
原创粉丝点击