Android——顶部弹出Snackbar

本文详细介绍了Android中如何实现和使用Snackbar,包括其基本用法、自定义样式以及与Activity、Fragment的交互,帮助开发者更好地进行UI提示信息的设计。
摘要由CSDN通过智能技术生成

 

public class TSnackbar {

    public static final int LENGTH_SHORT = -1;
    /**
     * Show the TSnackbar for a long period of time.
     */
    public static final int LENGTH_LONG = 0;

    private int residenceTime = 0;
    private View view;
    private static WeakReference<View> oldView;
    private String message;
    private int stateBarHeight, actionBarHeight;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    animateViewOut();
                    break;
            }
        }
    };


    public static TSnackbar make(View view, String message, int time) {
        TSnackbar tSnackbar2 = new TSnackbar();
        tSnackbar2.setDuration(time);
        tSnackbar2.setMessage(message);
        tSnackbar2.setView(view);
        return tSnackbar2;
    }

    public void show() {
        animateViewIn();
    }

    public void setMinHeight(int stateBarHeight, int actionBarHeight) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        params.height = stateBarHeight + actionBarHeight;
        view.setLayoutParams(params);
        this.stateBarHeight = stateBarHeight;
        this.actionBarHeight = actionBarHeight;
    }

    public void setView(View view) {
        if (oldView != null && oldView.get() != null) {
            View old = oldView.get();
            if (old.getParent() != null) {
                handler.removeMessages(1);
                ((ViewGroup) old.getParent()).removeView(old);
            }
        }
        ViewGroup viewGroup = findSuitableParent(view);
        if (viewGroup != null) {
            this.view = LayoutInflater.from(view.getContext()).inflate(R.layout.item_tsnack_bar, null);
          
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值