Giter VIP home page Giter VIP logo

loadingview's Introduction

LoadingView

耗时加载框和提示框。

图片展示:

展示1:耗时加载框

代码:

tipLoadDialog = new TipLoadDialog(this);
//默认是无阴影主题
tipLoadDialog.setMsgAndType(LOADING_玩命, TipLoadDialog.ICON_TYPE_LOADING).show();

展示2:耗时加载框,样式2

代码:

//设置另一种loading文字动画,注意不要加后缀...
tipLoadDialog.setNoShadowTheme()
        .setMsgAndType("加载中", TipLoadDialog.ICON_TYPE_LOADING2)
        .show();

展示3:tip提示框 1s后自动消失

代码:

//设置无阴影主题
tipLoadDialog.setNoShadowTheme().setMsgAndType(sucTip, TipLoadDialog.ICON_TYPE_SUCCESS).show();

展示4:阴影主题

代码:

//设置提示框阴影主题
tipLoadDialog.setShadowTheme().setMsgAndType(sucTip, TipLoadDialog.ICON_TYPE_SUCCESS).show();

展示5:设置圆角

代码:

//设置圆角
tipLoadDialog.setBackground(R.drawable.custom_dialog_bg_corner)
        .setNoShadowTheme()
        .setMsgAndType(LOADING_玩命, TipLoadDialog.ICON_TYPE_LOADING)
        .show();

展示6:设置icon

代码:

//设置除了Loading之外的tip图标
tipLoadDialog.setSuccessIcon(R.mipmap.custom_tip)
        .setMsgAndType(sucTip, TipLoadDialog.ICON_TYPE_SUCCESS)
        .show();

展示7:设置背景颜色

代码:

//设置背景颜色
tipLoadDialog.setBackground(R.drawable.custom_dialog_bg_color)
        .setNoShadowTheme()
        .setMsgAndType(sucTip, TipLoadDialog.ICON_TYPE_SUCCESS)
        .show();

展示8:设置提示文字颜色和大小

代码:

//设置提示信息的text的颜色和大小
tipLoadDialog.setNoShadowTheme()
        .setMsgColor(Color.BLUE)
        .setMsgSize(20)
        .setMsgAndType(failTip, TipLoadDialog.ICON_TYPE_FAIL)
        .show();

展示9:设置加载框文字颜色和大小,以及progressbar颜色

代码:

//设置加载框文字的颜色和大小 以及progressbar的颜色
tipLoadDialog.setNoShadowTheme()
        .setProgressbarColor(Color.RED)
        .setLoadingTextColor(Color.RED)
        .setLoadingTextSize(20)
        .setMsgAndType(LOADING_玩命, TipLoadDialog.ICON_TYPE_LOADING)
        .show();

展示10:设置加载一次文字动画时间

代码:

//设置loadingText一次动画的时间
tipLoadDialog.setNoShadowTheme()
        .setProgressbarColor(Color.WHITE)
        .setLoadingTextColor(Color.WHITE)
        .setLoadingTextSize(15)
        .setLoadingTime(10000)
        .setMsgAndType(LOADING_玩命, TipLoadDialog.ICON_TYPE_LOADING)
        .show();

展示11:弹窗消失事件监听

代码:(比如用在登陆成功跳转页面时候调用)

//弹窗消失事件监听
tipLoadDialog.setNoShadowTheme()
        .setMsgAndType("登录成功", TipLoadDialog.ICON_TYPE_SUCCESS)
        .setDismissListener(new TipLoadDialog.DismissListener()
        {
            @Override
            public void onDimissListener()
            {
                startActivity(new Intent(DialogTipActivity.this, HomeActivity.class));
                //然后可以finish掉当前登录页
            }
        })
        .show();

展示12:设置tip弹窗时间

代码:

//设置tip提示弹框时间
tipLoadDialog.setNoShadowTheme()
        .setMsgAndType("停留2秒消失", TipLoadDialog.ICON_TYPE_SUCCESS)
        .setTipTime(2000)
        .show();

两种实现模式:

一、采用Dialog模式实现:

缺点:必须得依赖Activity页面,所以很难用单例模式来生成,因为会造成内存泄漏。

优点:dialog本来就是为这个而生的,比较简单。

二、采用Toast模式实现:

缺点:无法像dialog一样能获取焦点,屏蔽其他控件事件。(比如正在加载网络请求时,页面其他控件是不能点击

​ 的,但是toast无法屏蔽事件)

优点:不依赖Activity,只需要Application即可。

duration时间问题。因为toast时间系统设置为固定的2秒和3.5秒。

使用toast需要解决两个问题:

①当duration不是2或者3.5秒时,怎么解决;

②当duration不确定时,怎么解决,比如正在进行网络请求;

解决方案:主要是利用了CountDownTimer类。Android自带的倒计时控件。

loadingview's People

Contributors

xiaocai9527 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.